|
20 | 20 | import com.iexec.common.config.PublicChainConfig; |
21 | 21 | import org.junit.jupiter.api.BeforeEach; |
22 | 22 | import org.junit.jupiter.api.Test; |
23 | | -import org.mockito.InjectMocks; |
24 | | -import org.mockito.Mock; |
25 | | -import org.mockito.MockitoAnnotations; |
26 | 23 | import org.springframework.http.ResponseEntity; |
27 | 24 |
|
28 | 25 | import java.time.Duration; |
29 | 26 |
|
30 | 27 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
31 | | -import static org.mockito.Mockito.when; |
32 | 28 |
|
33 | 29 | class PublicConfigurationControllerTests { |
34 | 30 |
|
35 | | - @Mock |
36 | | - ChainConfig chainConfig; |
| 31 | + private static final int ID = 65535; |
| 32 | + private static final String NODE_ADDRESS = "http://localhost:8545"; |
| 33 | + private static final String HUB_ADDRESS = "0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca"; |
| 34 | + private static final int BLOCK_TIME = 5; |
| 35 | + private static final boolean IS_SIDECHAIN = true; |
| 36 | + |
| 37 | + ChainConfig chainConfig = ChainConfig.builder() |
| 38 | + .id(ID) |
| 39 | + .nodeAddress(NODE_ADDRESS) |
| 40 | + .hubAddress(HUB_ADDRESS) |
| 41 | + .blockTime(BLOCK_TIME) |
| 42 | + .isSidechain(IS_SIDECHAIN) |
| 43 | + .build(); |
37 | 44 |
|
38 | | - @InjectMocks |
39 | 45 | PublicConfigurationController controller; |
40 | 46 |
|
41 | 47 | @BeforeEach |
42 | 48 | void init() { |
43 | | - MockitoAnnotations.openMocks(this); |
| 49 | + controller = new PublicConfigurationController(chainConfig); |
44 | 50 | } |
45 | 51 |
|
46 | 52 | @Test |
47 | 53 | void shouldReturnConfig() { |
48 | | - int blockTime = 5; |
49 | 54 | PublicChainConfig expectedConfig = PublicChainConfig |
50 | 55 | .builder() |
51 | | - .sidechain(true) |
52 | | - .chainId(65535) |
53 | | - .chainNodeUrl("http://localhost:8545") |
54 | | - .iexecHubContractAddress("0xC129e7917b7c7DeDfAa5Fff1FB18d5D7050fE8ca") |
55 | | - .blockTime(Duration.ofSeconds(blockTime)) |
| 56 | + .sidechain(IS_SIDECHAIN) |
| 57 | + .chainId(ID) |
| 58 | + .chainNodeUrl(NODE_ADDRESS) |
| 59 | + .iexecHubContractAddress(HUB_ADDRESS) |
| 60 | + .blockTime(Duration.ofSeconds(BLOCK_TIME)) |
56 | 61 | .build(); |
57 | | - when(chainConfig.getChainId()).thenReturn(expectedConfig.getChainId()); |
58 | | - when(chainConfig.isSidechain()).thenReturn(expectedConfig.isSidechain()); |
59 | | - when(chainConfig.getNodeAddress()).thenReturn(expectedConfig.getChainNodeUrl()); |
60 | | - when(chainConfig.getHubAddress()).thenReturn(expectedConfig.getIexecHubContractAddress()); |
61 | | - when(chainConfig.getBlockTime()).thenReturn(blockTime); |
62 | 62 | ResponseEntity<PublicChainConfig> response = controller.getPublicChainConfig(); |
63 | 63 | assertThat(response.getBody()) |
64 | 64 | .isNotNull() |
|
0 commit comments