Skip to content

Commit

Permalink
Add tests. Fix line termination in test data.
Browse files Browse the repository at this point in the history
  • Loading branch information
tntim96 committed Oct 27, 2012
1 parent cd16d7b commit 788ada4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
</target>

<target name="coverage-check">
<cobertura-check totallinerate="80" totalbranchrate="79"/>
<cobertura-check totallinerate="80" totalbranchrate="81"/>
</target>

<target name="coverage-check-all">
Expand Down
45 changes: 41 additions & 4 deletions src/test/java/jscover/server/InstrumentingRequestHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,7 @@ You should also get your employer (if you work as a programmer) or your
import org.mockito.runners.MockitoJUnitRunner;
import org.mozilla.javascript.CompilerEnvirons;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
Expand All @@ -370,6 +367,7 @@ You should also get your employer (if you work as a programmer) or your

import static java.lang.String.format;
import static jscover.server.InstrumentingRequestHandler.JSCOVERAGE_STORE;
import static org.hamcrest.CoreMatchers.any;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -426,6 +424,45 @@ public void shouldStoreJSCoverageJSON() {
assertThat(stringWriter.toString(), containsString(format("Coverage data stored at %s", reportDir)));
}

@Test
public void shouldDirectPOSTToHttpServer() {
given(configuration.isProxy()).willReturn(false);

HttpRequest request = new HttpRequest("somePostUrl");
webServer.handlePost(request, "thePostData");

verifyZeroInteractions(ioService);
verifyZeroInteractions(jsonDataSaver);
verifyZeroInteractions(instrumenterService);
assertThat(stringWriter.toString(), containsString("thePostData"));
}

@Test
public void shouldDirectGETToProxy() throws IOException {
given(configuration.isProxy()).willReturn(true);

HttpRequest request = new HttpRequest("somePostUrl");
webServer.handleGet(request);

verify(proxyService).handleProxyGet(request, null);
verifyZeroInteractions(ioService);
verifyZeroInteractions(jsonDataSaver);
verifyZeroInteractions(instrumenterService);
}

@Test
public void shouldDirectPOSTToProxy() {
given(configuration.isProxy()).willReturn(true);

HttpRequest request = new HttpRequest("somePostUrl");
webServer.handlePost(request, "data");

verify(proxyService).handleProxyPost(request, "data", null);
verifyZeroInteractions(ioService);
verifyZeroInteractions(jsonDataSaver);
verifyZeroInteractions(instrumenterService);
}

@Test
public void shouldHandleErrorOnStoreJSCoverageJSON() {
File reportDir = new File("target/temp");
Expand Down

0 comments on commit 788ada4

Please sign in to comment.