Same tests with Mock
This commit is contained in:
@@ -1,17 +1,45 @@
|
|||||||
package session4;
|
package session4;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
import com.squeed.kata.nametag.NameTagManager;
|
import com.squeed.kata.nametag.NameTagManager;
|
||||||
import com.squeed.kata.nametag.entities.Attendee;
|
import com.squeed.kata.nametag.entities.Attendee;
|
||||||
import com.squeed.kata.nametag.entities.Event;
|
import com.squeed.kata.nametag.entities.Event;
|
||||||
|
import com.squeed.kata.nametag.services.PrintingService;
|
||||||
|
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class TagManagerTest {
|
public class TagManagerTest {
|
||||||
|
private NameTagManagerImpl testee;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Event event;
|
||||||
|
@Mock
|
||||||
|
private PrintingService printingService;
|
||||||
|
@Mock
|
||||||
|
private Attendee a_person;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Image defaultImage;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup(){
|
||||||
|
testee = new NameTagManagerImpl(printingService);
|
||||||
|
|
||||||
|
Mockito.when(event.getDefaultImage()).thenReturn(defaultImage);
|
||||||
|
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
public void when_event_is_empty_nothing_is_printed() throws Exception {
|
public void when_event_is_empty_nothing_is_printed() throws Exception {
|
||||||
Event event = new EmptyEvent();
|
Event event = new EmptyEvent();
|
||||||
@@ -36,7 +64,24 @@ public class TagManagerTest {
|
|||||||
testee.printNameTagsForEvent(event);
|
testee.printNameTagsForEvent(event);
|
||||||
|
|
||||||
assertEquals(defaultImage, printingService.getPrintedImage(0));
|
assertEquals(defaultImage, printingService.getPrintedImage(0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void same_As_first_test_with_mock() throws Exception {
|
||||||
|
|
||||||
|
testee.printNameTagsForEvent(event);
|
||||||
|
|
||||||
|
Mockito.verifyZeroInteractions(printingService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void same_as_second_test_with_mock() throws Exception {
|
||||||
|
List<Attendee> persons = Arrays.asList(a_person);
|
||||||
|
Mockito.when(event.getExpectedAttendees()).thenReturn(persons);
|
||||||
|
|
||||||
|
testee.printNameTagsForEvent(event);
|
||||||
|
|
||||||
|
Mockito.verify(printingService).printNameTagFor(a_person, defaultImage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user