I have written this test class to check a service. This is in folder test/java/example/demp/Test.java
@RunWith(MockitoJUnitRunner.class)
@TestPropertySource("classpath:conn.properties")
public class DisplayServiceTest {
@Value("${id}")
private String value;
@Mock
private DisplayRepository DisplayReps;
@InjectMocks
private DisplayService DisplayService;
@Test
public void whenFindAll_thenReturnProductList() {
Menu m = new Menu()
m.setId(value); //when I print value its showing 0
List<Display> expectedDisplay = Arrays.asList(m);
doReturn(expectedDisplay).when(DisplayReps).findAll();
List<Display> actualDisplay = DisplayService.findAll();
assertThat(actualDisplay).isEqualTo(expectedDisplay);
}
My properties file This is in folder test/resources/conn.properties
id=2
What is the right way to set properties from custom properties file? Cause its not loading values ?