Skip to content

Commit

Permalink
better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Mar 18, 2015
1 parent 0975fe0 commit 228af24
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ private void startServer(WebappContext webappContext, HttpServer httpServer, Com
.getModule().getContext(), serverData.getPort());
logger.info("Browse to http://localhost:{}/{}/application.wadl",
serverData.getPort(), serverData.getModule().getContext());
serverData.logResources("http://localhost:"+serverData.getPort()+"/"+serverData.getModule().getContext());
logger.info("Configured resource classes :-");
serverData.extractResources()
.forEach(t -> logger.info(t.v1 + " : " + "http://localhost:"+serverData.getPort()
+"/"+serverData.getModule().getContext() + t.v2 ));;
httpServer.start();
start.complete(true);
end.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import static org.jooq.lambda.tuple.Tuple.tuple;

import java.util.List;
import java.util.stream.Stream;

import javax.ws.rs.Path;

import lombok.Getter;
import lombok.experimental.Builder;

import org.jooq.lambda.tuple.Tuple;
import org.jooq.lambda.tuple.Tuple2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -41,11 +42,11 @@ public ServerData(int port, List resources,
this.baseUrlPattern = baseUrlPattern;
}

public void logResources(String url) {
public Stream<Tuple2<String,String>> extractResources() {

logger.info("Configured resource classes :-");
resources.stream().map(resource -> tuple(resource.getClass().getName(), resource.getClass().getAnnotation(Path.class).value()))
.forEach(t -> logger.info(t.v1 + " : " + url + t.v2 ));

return resources.stream().map(resource -> tuple(resource.getClass().getName(),
resource.getClass().getAnnotation(Path.class).value()));


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import java.util.stream.Collectors;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -37,19 +37,26 @@ public void testGetters() {
}

@Test(expected=NullPointerException.class)
public void testLogNull(){
public void testExtractNull(){

serverData = new ServerData(8080, Lists.newArrayList((Object)null), rootContext, "url",
()->"context");
serverData.logResources("url");
serverData.extractResources();

}

@Test
public void testLog(){
public void testExtractResourceClassName(){


assertThat(serverData.extractResources().collect(Collectors.toList()).get(0).v1,is(ServletStatusResource.class.getName()));

}
@Test
public void testExtractResourcePath(){


serverData.logResources("http://localhost:8080/hello");
assertThat(serverData.extractResources().collect(Collectors.toList()).get(0).v2,is("/servlet"));

}

Expand Down

0 comments on commit 228af24

Please sign in to comment.