Skip to content

Commit

Permalink
added message to assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jett Gamboa authored and Jett Gamboa committed Dec 29, 2015
1 parent 4dec47a commit d6220f0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
32 changes: 22 additions & 10 deletions src/test/java/spark/route/RouteEntryTest.java
Expand Up @@ -16,7 +16,9 @@ public void testMatches_BeforeAndAllPaths() {
entry.httpMethod = HttpMethod.before;
entry.path = SparkUtils.ALL_PATHS;

assertTrue(entry.matches(HttpMethod.before, SparkUtils.ALL_PATHS));
assertTrue("Should return true because HTTP method is \"Before\", the methods of route and match request match," +
" and the path provided is same as ALL_PATHS (+/*paths)",
entry.matches(HttpMethod.before, SparkUtils.ALL_PATHS));
}

@Test
Expand All @@ -26,7 +28,9 @@ public void testMatches_AfterAndAllPaths() {
entry.httpMethod = HttpMethod.after;
entry.path = SparkUtils.ALL_PATHS;

assertTrue(entry.matches(HttpMethod.after, SparkUtils.ALL_PATHS));
assertTrue("Should return true because HTTP method is \"After\", the methods of route and match request match," +
" and the path provided is same as ALL_PATHS (+/*paths)",
entry.matches(HttpMethod.after, SparkUtils.ALL_PATHS));
}

@Test
Expand All @@ -36,7 +40,8 @@ public void testMatches_NotAllPathsAndDidNotMatchHttpMethod() {
entry.httpMethod = HttpMethod.post;
entry.path = "/test";

assertFalse(entry.matches(HttpMethod.get, "/path"));
assertFalse("Should return false because path names did not match",
entry.matches(HttpMethod.get, "/path"));
}

@Test
Expand All @@ -46,7 +51,9 @@ public void testMatches_RouteDoesNotEndWithSlash() {
entry.httpMethod = HttpMethod.get;
entry.path = "/test";

assertFalse(entry.matches(HttpMethod.get, "/test/"));
assertFalse("Should return false because route path does not end with a slash, does not end with " +
"a wildcard, and the route pah supplied ends with a slash ",
entry.matches(HttpMethod.get, "/test/"));
}

@Test
Expand All @@ -56,7 +63,8 @@ public void testMatches_PathDoesNotEndInSlash() {
entry.httpMethod = HttpMethod.get;
entry.path = "/test/";

assertFalse(entry.matches(HttpMethod.get, "/test"));
assertFalse("Should return false because route path ends with a slash while path supplied as parameter does" +
"not end with a slash", entry.matches(HttpMethod.get, "/test"));
}

@Test
Expand All @@ -66,7 +74,8 @@ public void testMatches_MatchingPaths() {
entry.httpMethod = HttpMethod.get;
entry.path = "/test/";

assertTrue(entry.matches(HttpMethod.get, "/test/"));
assertTrue("Should return true because route path and path is exactly the same",
entry.matches(HttpMethod.get, "/test/"));
}

@Test
Expand All @@ -76,7 +85,8 @@ public void testMatches_WithWildcardOnEntryPath() {
entry.httpMethod = HttpMethod.get;
entry.path = "/test/*";

assertTrue(entry.matches(HttpMethod.get, "/test/me"));
assertTrue("Should return true because path specified is covered by the route path wildcard",
entry.matches(HttpMethod.get, "/test/me"));
}

@Test
Expand All @@ -86,17 +96,19 @@ public void testMatches_PathsDoNotMatch() {
entry.httpMethod = HttpMethod.get;
entry.path = "/test/me";

assertFalse(entry.matches(HttpMethod.get, "/test/other"));
assertFalse("Should return false because path does not match route path",
entry.matches(HttpMethod.get, "/test/other"));
}

@Test
public void testMatches_routePathWildcard() {
public void testMatches_longRoutePathWildcard() {

RouteEntry entry = new RouteEntry();
entry.httpMethod = HttpMethod.get;
entry.path = "/test/this/resource/*";

assertTrue(entry.matches(HttpMethod.get, "/test/this/resource/child/id"));
assertTrue("Should return true because path specified is covered by the route path wildcard",
entry.matches(HttpMethod.get, "/test/this/resource/child/id"));
}

}
9 changes: 7 additions & 2 deletions src/test/java/spark/utils/MimeParseTest.java
Expand Up @@ -16,7 +16,9 @@ public void testBestMatch() throws Exception {

Collection<String> supported = Arrays.asList("application/xml", "text/html");

assertEquals("text/html", MimeParse.bestMatch(supported, header));
assertEquals("bestMatch should return the supported mime type with the highest quality factor" +
"because it is preferred mime type as indicated in the HTTP header",
"text/html", MimeParse.bestMatch(supported, header));

}

Expand All @@ -27,7 +29,10 @@ public void testBestMatch_whenSupportedIsLowQualityFactor() throws Exception {

Collection<String> supported = Arrays.asList("application/json");

assertEquals("application/json", MimeParse.bestMatch(supported, header));
assertEquals("bestMatch should return the mime type even if it is not included in the supported" +
"mime types because it is considered by the */* all media type specified in the Accept" +
"Header",
"application/json", MimeParse.bestMatch(supported, header));

}

Expand Down
27 changes: 22 additions & 5 deletions src/test/java/spark/utils/SparkUtilsTest.java
Expand Up @@ -18,22 +18,39 @@ public void testConvertRouteToList() throws Exception {

List<String> actual = SparkUtils.convertRouteToList("/api/person/:id");

assertThat(actual, is(expected));
assertThat("Should return route as a list of individual elements that path is made of",
is(expected));

}

@Test
public void testIsParam() throws Exception {
public void testIsParam_whenParameterFormattedAsParm() throws Exception {

assertTrue(SparkUtils.isParam(":param"));
assertTrue("Should return true because parameter follows convention of a parameter (:paramname)",
SparkUtils.isParam(":param"));

}

@Test
public void testIsParam_whenParameterNotFormattedAsParm() throws Exception {

assertFalse("Should return false because parameter does not follows convention of a parameter (:paramname)",
SparkUtils.isParam(".param"));

}


@Test
public void testIsSplat_whenParameterIsASplat() throws Exception {

assertTrue("Should return true because parameter is a splat (*)", SparkUtils.isSplat("*"));

}

@Test
public void testIsSplat() throws Exception {
public void testIsSplat_whenParameterIsNotASplat() throws Exception {

assertTrue(SparkUtils.isSplat("*"));
assertFalse("Should return true because parameter is not a splat (*)", SparkUtils.isSplat("!"));

}
}

0 comments on commit d6220f0

Please sign in to comment.