Created
September 5, 2011 00:46
-
-
Save coderunner/1193799 to your computer and use it in GitHub Desktop.
Revisions
-
coderunner revised this gist
Sep 5, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ public class TestExampleRequestHandler_Mockito { private static final String STORE_BODY = "stored body"; private static final String CASE_HEADER = "case"; private static final String UPPERCASE = "uppercase"; private static final String REQUEST_PATH = "path"; private ExampleRequestHandler requestHandler; @@ -53,7 +53,7 @@ public void shouldIncrementRequestCounter() @Test public void shouldConvertToUpperCaseIfHeaderValuePresent() { when(headers.get(CASE_HEADER)).thenReturn(UPPERCASE); HttpResponse response = requestHandler.handle(request, context); assertEquals(STORE_BODY.toUpperCase(), response.getBody()); -
coderunner revised this gist
Sep 5, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,7 @@ public void shouldIncrementRequestCounter() } @Test public void shouldConvertToUpperCaseIfHeaderValuePresent() { when(headers.get(CASE_HEADER)).thenReturn(CASE_HEADER_VALUE); -
coderunner created this gist
Sep 5, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ public class TestExampleRequestHandler_Mockito { private static final String STORE_BODY = "stored body"; private static final String CASE_HEADER = "case"; private static final String CASE_HEADER_VALUE = "uppercase"; private static final String REQUEST_PATH = "path"; private ExampleRequestHandler requestHandler; private HttpRequest request; private Context context; private Monitoring monitoring; private Store store; private Map<String, String> headers; @Before public void setup() { requestHandler = new ExampleRequestHandler(); request = mock(HttpRequest.class); context = mock(Context.class); monitoring = mock(Monitoring.class); store = mock(Store.class); headers = mock(Map.class); when(context.getMonitoring()).thenReturn(monitoring); when(context.getStore()).thenReturn(store); when(store.get(REQUEST_PATH)).thenReturn(STORE_BODY); when(request.getPath()).thenReturn(REQUEST_PATH); when(request.getHeaders()).thenReturn(headers); } @Test public void shouldReturnTheStoredBody() { HttpResponse response = requestHandler.handle(request, context); assertEquals(STORE_BODY, response.getBody()); } @Test public void responseCodeShouldBe200() { HttpResponse response = requestHandler.handle(request, context); assertEquals(200, response.getCode()); } @Test public void shouldIncrementRequestCounter() { requestHandler.handle(request, context); verify(monitoring).incrementRequestCounter(); } @Test public void shouldConvertToUpperCaseIfHeaderPresent() { when(headers.get(CASE_HEADER)).thenReturn(CASE_HEADER_VALUE); HttpResponse response = requestHandler.handle(request, context); assertEquals(STORE_BODY.toUpperCase(), response.getBody()); } }