Created
December 7, 2010 15:24
-
-
Save amolbrid/731901 to your computer and use it in GitHub Desktop.
RequestProcessorTest class for Mockito invocation order blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.mockito.Mockito.verify; | |
import static org.mockito.Mockito.when; | |
import static org.mockito.Mockito.*; | |
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.net.Socket; | |
import junit.framework.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.mockito.InOrder; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
public class RequestProcessorTest { | |
@Mock private Socket socketMock; | |
@Before public void initMock() { | |
MockitoAnnotations.initMocks(this); | |
} | |
@Test public void socketClosedInIdealCase() throws IOException { | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
ByteArrayInputStream bais = new ByteArrayInputStream("a=b+c".getBytes()); | |
when(socketMock.getInputStream()).thenReturn(bais); | |
when(socketMock.getOutputStream()).thenReturn(baos); | |
RequestProcessor request = new RequestProcessor(socketMock); | |
request.process(); | |
InOrder order = inOrder(socketMock); | |
order.verify(socketMock).getInputStream(); | |
order.verify(socketMock).getOutputStream(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment