|
| 1 | +package com.iluwatar.front.controller; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | +import org.junit.runner.RunWith; |
| 5 | +import org.junit.runners.Parameterized; |
| 6 | +import org.junit.runners.Parameterized.Parameters; |
| 7 | + |
| 8 | +import java.util.ArrayList; |
| 9 | +import java.util.List; |
| 10 | + |
| 11 | +import static org.mockito.Mockito.verify; |
| 12 | +import static org.mockito.Mockito.verifyNoMoreInteractions; |
| 13 | +import static org.mockito.Mockito.verifyZeroInteractions; |
| 14 | + |
| 15 | +/** |
| 16 | + * Date: 12/13/15 - 1:39 PM |
| 17 | + * |
| 18 | + * @author Jeroen Meulemeester |
| 19 | + */ |
| 20 | +@RunWith(Parameterized.class) |
| 21 | +public class CommandTest extends StdOutTest { |
| 22 | + |
| 23 | + @Parameters |
| 24 | + public static List<Object[]> data() { |
| 25 | + final List<Object[]> parameters = new ArrayList<>(); |
| 26 | + parameters.add(new Object[]{"Archer", "Displaying archers"}); |
| 27 | + parameters.add(new Object[]{"Catapult", "Displaying catapults"}); |
| 28 | + parameters.add(new Object[]{"NonExistentCommand", "Error 500"}); |
| 29 | + return parameters; |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * The view that's been tested |
| 34 | + */ |
| 35 | + private final String request; |
| 36 | + |
| 37 | + /** |
| 38 | + * The expected display message |
| 39 | + */ |
| 40 | + private final String displayMessage; |
| 41 | + |
| 42 | + /** |
| 43 | + * Create a new instance of the {@link CommandTest} with the given view and expected message |
| 44 | + * |
| 45 | + * @param request The request that's been tested |
| 46 | + * @param displayMessage The expected display message |
| 47 | + */ |
| 48 | + public CommandTest(final String request, final String displayMessage) { |
| 49 | + this.displayMessage = displayMessage; |
| 50 | + this.request = request; |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testDisplay() { |
| 55 | + final FrontController frontController = new FrontController(); |
| 56 | + verifyZeroInteractions(getStdOutMock()); |
| 57 | + frontController.handleRequest(request); |
| 58 | + verify(getStdOutMock()).println(displayMessage); |
| 59 | + verifyNoMoreInteractions(getStdOutMock()); |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments