Load properties when MockitoJUnitRunner is used

Viewed 2628

I'm trying to load a property value from my application-test.properties in my service unit tests(using MockitoJUnitRunner.class) but it gets always a null value using @Value annotation.

@RunWith(MockitoJUnitRunner.class)
public class AlertQueryServiceImplTest {

@Value("${raw.path}")
private static String rawJson;

@InjectMocks
private AlertQueryServiceImpl alertQueryServiceImpl;

@Mock
private AlertCBDAOImpl alertCBDAOImpl;

private List<Alert> alertListExpected;

@Before
public void setUp() {
    ReflectionTestUtils.setField(alertQueryServiceImpl, "url", "http://someurl");
    alertListExpected = JsonUtils.
            loadObjectList(Alert.class, JsonUtils.ALERTS_FILE);
    assertFalse(alertListExpected.isEmpty());
}

@Test
public void shouldReturnAlerts() {
    User userTest = new User("108998", "3000747091");
    JsonDocument jsonDocExpected = JsonUtils.stringToJsonDocument(rawJson, userTest.getAssociatedBE());

    when(alertCBDAOImpl.getDoc(userTest.getAssociatedBE())).thenReturn(jsonDocExpected);
    when(alertCBDAOImpl.getAlerts(jsonDocExpected)).thenReturn(alertListExpected);
}
}

How could I load raw.path property into rawJson field?

1 Answers
Related