I have a class Room
, where I inject Optional Person
object, this is coming null while running testSuccess
. My understanding is it should come non null, since I am setting this to new Person()
at the start of the test. Why is it coming null?
public class Room{
@Inject
private Optional<Person> person1
//this is coming null when running test
}
My unit test
public class RoomTest {
@Inject Mocks
private Room testRoom
.....
//Other mocks
private Optional<Person> testPerson
//Not able to mock this since its optional, hence directly setting value in unit test.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void testSuccess() {
testPerson = Optional.of(new Person());
....
}
}