Reputation: 57
How can i use mock objects in this junit testing?? I need to implement mock objects in junit. Need help in regarding this code.
public class TicketTest {
public static List<Ticket> tickList = new ArrayList<Ticket>();
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void objectValueSetting() throws Exception {
Ticket ticket = new Ticket();
ticket.setDescription("helllo");
ticket.setEmail("[email protected]");
tickList.add(ticket);
}
@Test
public void valueGetting() throws Exception {
Ticket ticket = tickList.get(0);
Assert.assertNotNull(ticket);
Assert.assertNotNull(ticket.getDescription());
Assert.assertNotNull(ticket.getEmail());
}
}
Upvotes: 0
Views: 706
Reputation: 36
What do you want to mock ? (Not able to comment. So writing it here) If you want to mock Ticket Class then the code will look like
` @Test public void valueGetting() throws Exception {
Ticket mock= Mockito.mock(Ticket.class);
when(mock.getDescription()).thenReturn("hello");
when(mock.getEmail()).thenReturn("[email protected]");
Assert.assertNotNull(mock);
Assert.assertNotNull(mock.getDescription());
Assert.assertNotNull(mock.getEmail());
}
`
PS : I am using mockito.
Upvotes: 1