|
1 | | -/* |
| 1 | +/* |
2 | 2 | * Copyright 2018 The Exonum Team |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
16 | 16 |
|
17 | 17 | package ${package}; |
18 | 18 |
|
19 | | -import static org.hamcrest.CoreMatchers.instanceOf; |
20 | 19 | import static org.hamcrest.MatcherAssert.assertThat; |
| 20 | +import static org.hamcrest.Matchers.equalTo; |
21 | 21 |
|
22 | | -import com.exonum.binding.core.service.Service; |
23 | | -import com.exonum.binding.core.service.TransactionConverter; |
24 | | -import com.google.inject.Guice; |
25 | | -import com.google.inject.Injector; |
| 22 | +import com.exonum.binding.core.blockchain.Blockchain; |
| 23 | +import com.exonum.binding.testkit.TestKit; |
26 | 24 | import org.junit.jupiter.api.Test; |
27 | 25 |
|
28 | 26 | class ServiceModuleTest { |
29 | 27 |
|
| 28 | + /** |
| 29 | + * This is an example service integration test with Exonum Testkit. It simply verifies |
| 30 | + * that a Service can be instantiated by Testkit, and that the libraries required for Testkit |
| 31 | + * operation are accessible. |
| 32 | + * |
| 33 | + * <p>If you get an UnsatisfiedLinkError in this test — please check that the EXONUM_HOME |
| 34 | + * environment variable is set properly: |
| 35 | + * https://exonum.com/doc/version/latest/get-started/java-binding/#after-install |
| 36 | + */ |
30 | 37 | @Test |
31 | | - void testServiceBinding() { |
32 | | - Injector injector = createInjector(); |
33 | | - |
34 | | - Service s = injector.getInstance(Service.class); |
35 | | - |
36 | | - assertThat(s, instanceOf(MyService.class)); |
37 | | - } |
38 | | - |
39 | | - @Test |
40 | | - void testTransactionConverterBinding() { |
41 | | - Injector injector = createInjector(); |
42 | | - |
43 | | - TransactionConverter s = injector.getInstance(TransactionConverter.class); |
44 | | - |
45 | | - assertThat(s, instanceOf(MyTransactionConverter.class)); |
46 | | - } |
47 | | - |
48 | | - private static Injector createInjector() { |
49 | | - return Guice.createInjector(new ServiceModule()); |
| 38 | + void testServiceInstantiation() { |
| 39 | + try (TestKit testKit = TestKit.forService(ServiceModule.class)) { |
| 40 | + MyService service = testKit.getService(MyService.ID, MyService.class); |
| 41 | + |
| 42 | + // Check that genesis block was committed |
| 43 | + testKit.withSnapshot((view) -> { |
| 44 | + Blockchain blockchain = Blockchain.newInstance(view); |
| 45 | + assertThat(blockchain.getBlockHashes().size(), equalTo(1L)); |
| 46 | + }); |
| 47 | + } |
50 | 48 | } |
51 | 49 | } |
0 commit comments