Skip to content

Commit

Permalink
UTS-199 - Add test case for RouteImplTest and FilterImplTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Sztul authored and Jett Gamboa committed Jan 1, 2016
1 parent cb79078 commit 65cf5d3
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<properties>
<jetty.version>9.3.6.v20151106</jetty.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<easymock.version>3.2</easymock.version>
<powermock.version>1.6.4</powermock.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -79,6 +81,18 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>${easymock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock.tests</groupId>
<artifactId>powermock-tests-utils</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
Expand Down
52 changes: 52 additions & 0 deletions src/test/java/spark/FilterImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package spark;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class FilterImplTest {

public String PATH_TEST;
public String ACCEPT_TYPE_TEST;

public FilterImpl filter;

@Before
public void setup(){
PATH_TEST = "/etc/test";
ACCEPT_TYPE_TEST = "test/*";
}

@Test
public void testConstructor(){
FilterImpl filter = new FilterImpl(PATH_TEST, ACCEPT_TYPE_TEST) {
@Override
public void handle(Request request, Response response) throws Exception {
}
};
assertEquals("Path is not equal", PATH_TEST, filter.getPath());
assertEquals("Accept type is not equal", ACCEPT_TYPE_TEST, filter.getAcceptType());
}

@Test
public void testGets() throws Exception {
filter = FilterImpl.create(PATH_TEST, ACCEPT_TYPE_TEST, null);
assertEquals("Path is not equal", PATH_TEST, filter.getPath());
assertEquals("Accept type is not equal", ACCEPT_TYPE_TEST, filter.getAcceptType());
}

@Test
public void testCreate_withOutAssignAcceptTypeInTheParameters(){
filter = FilterImpl.create(PATH_TEST, null);
assertEquals("Path is not equal", PATH_TEST, filter.getPath());
assertEquals("Accept type is not equal", RouteImpl.DEFAULT_ACCEPT_TYPE, filter.getAcceptType());
}

@Test
public void testCreate_withAcceptTypeNullValueInTheParameters(){
filter = FilterImpl.create(PATH_TEST, null, null);
assertEquals("Path is not equal", PATH_TEST, filter.getPath());
assertEquals("Accept type is not equal", RouteImpl.DEFAULT_ACCEPT_TYPE, filter.getAcceptType());
}
}
84 changes: 84 additions & 0 deletions src/test/java/spark/RouteImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package spark;

import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;

import static junit.framework.TestCase.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class RouteImplTest {

public String PATH_TEST;
public String ACCEPT_TYPE_TEST;

public RouteImpl route;

@Before
public void setup(){
PATH_TEST = "/opt/test";
ACCEPT_TYPE_TEST = "*/test";
}

@Test
public void testConstructor(){
RouteImpl route = new RouteImpl(PATH_TEST) {
@Override
public Object handle(Request request, Response response) throws Exception {
return null;
}
};
assertEquals("Path is not equal", PATH_TEST, route.getPath());
}

@Test
public void testGets() throws Exception {
route = RouteImpl.create(PATH_TEST, ACCEPT_TYPE_TEST, null);
assertEquals("Path is not equal", PATH_TEST, route.getPath());
assertEquals("Accept type is not equal", ACCEPT_TYPE_TEST, route.getAcceptType());
}

@Test
public void testHandle() throws Exception {
Route routeMock = EasyMock.createMock(Route.class);
RouteImpl route = RouteImpl.create(PATH_TEST, routeMock);

EasyMock.expect(route.handle(null, null)).andReturn(new Object());

EasyMock.replay(routeMock);
Object value = route.handle(null, null);
EasyMock.verify(routeMock);

assertNotNull("Value is null", value);
}

@Test
public void testCreate_withOutAssignAcceptTypeInTheParameters(){
route = RouteImpl.create(PATH_TEST, null);
assertEquals("Path is not equal", PATH_TEST, route.getPath());
assertEquals("Accept type is not equal", RouteImpl.DEFAULT_ACCEPT_TYPE, route.getAcceptType());
}

@Test
public void testCreate_withAcceptTypeNullValueInTheParameters(){
route = RouteImpl.create(PATH_TEST, null, null);
assertEquals("Path is not equal", PATH_TEST, route.getPath());
assertEquals("Accept type is not equal", RouteImpl.DEFAULT_ACCEPT_TYPE, route.getAcceptType());
}

@Test
public void testRender_withElementParameterValid_thenReturnValidObject() throws Exception {
route = RouteImpl.create(PATH_TEST, null);
Object value = route.render("object_value");
assertNotNull("Value is null", value);
assertEquals("Value is not equal", "object_value", value.toString());
}

@Test
public void testRender_withElementParameterIsNull_thenReturnNull() throws Exception {
route = RouteImpl.create(PATH_TEST, null);
Object value = route.render(null);
assertNull("Value is not null", value);
}
}

0 comments on commit 65cf5d3

Please sign in to comment.