From d6220f0aecbb05a962725e298098890acba3acc7 Mon Sep 17 00:00:00 2001 From: Jett Gamboa Date: Mon, 21 Dec 2015 22:16:18 +0800 Subject: [PATCH] added message to assertions --- src/test/java/spark/route/RouteEntryTest.java | 32 +++++++++++++------ src/test/java/spark/utils/MimeParseTest.java | 9 ++++-- src/test/java/spark/utils/SparkUtilsTest.java | 27 +++++++++++++--- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/test/java/spark/route/RouteEntryTest.java b/src/test/java/spark/route/RouteEntryTest.java index 6b5d06915a..c0ba59a2e9 100644 --- a/src/test/java/spark/route/RouteEntryTest.java +++ b/src/test/java/spark/route/RouteEntryTest.java @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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")); } } \ No newline at end of file diff --git a/src/test/java/spark/utils/MimeParseTest.java b/src/test/java/spark/utils/MimeParseTest.java index 9a63613642..5b5478455c 100644 --- a/src/test/java/spark/utils/MimeParseTest.java +++ b/src/test/java/spark/utils/MimeParseTest.java @@ -16,7 +16,9 @@ public void testBestMatch() throws Exception { Collection 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)); } @@ -27,7 +29,10 @@ public void testBestMatch_whenSupportedIsLowQualityFactor() throws Exception { Collection 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)); } diff --git a/src/test/java/spark/utils/SparkUtilsTest.java b/src/test/java/spark/utils/SparkUtilsTest.java index 7fcf9efb85..723a268e0c 100644 --- a/src/test/java/spark/utils/SparkUtilsTest.java +++ b/src/test/java/spark/utils/SparkUtilsTest.java @@ -18,22 +18,39 @@ public void testConvertRouteToList() throws Exception { List 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("!")); } } \ No newline at end of file