package testingWS;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import First.Track;
import First.User;
import First.UserWebService;
import Service.TrackService;
import Service.UserService;
public class TestingDuringDevelopment {
@Mock
private UserService userService;
@Mock TrackService trackService;
@InjectMocks
private UserWebService userWebServiceMock=new UserWebService();
@Before
public void testBefore() {
MockitoAnnotations.initMocks(this);
User user = new User();
user.setId(12);
user.setFirstName("Tim");
user.setLastName("Tester");
when(userService.getUser(12)).thenReturn(user);
Track track = new Track();
track.setTitle("AWMAWY");
track.setSinger("Joe Satriani");
when(trackService.getTrack()).thenReturn(track);
}
@Test
public void testTrack(){
Track track= userWebServiceMock.getTrackInJSON();
Track newTrack=new Track();
newTrack.setSinger("Joe Satriani");
newTrack.setTitle("AWMAWY");
assertEquals(track.getSinger(), newTrack.getSinger());
assertEquals(track.getTitle(), newTrack.getTitle());
verify(trackService);
}
}
No comments:
Post a Comment