diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-19 14:21:48 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-19 14:21:48 +0100 |
commit | 87ed9372267b3e73714b6f0130b86eb29d3e23d7 (patch) | |
tree | c0b9754e5c230df9cb6f2ff7c93727ee7bb27e7e /vespaclient-container-plugin | |
parent | 63da9a412b31fb1badc787e4ae8550a0c2b50fc0 (diff) |
Simnplify testing by sticking to assertEquals/True/False
Diffstat (limited to 'vespaclient-container-plugin')
3 files changed, 50 insertions, 53 deletions
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/FeedHandlerCompressionTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/FeedHandlerCompressionTest.java index 01784226c9e..6f1b5eebcc4 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/FeedHandlerCompressionTest.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/FeedHandlerCompressionTest.java @@ -10,8 +10,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.zip.GZIPOutputStream; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -42,7 +41,7 @@ public class FeedHandlerCompressionTest { } processedInput.append((char)readValue); } - assertThat(processedInput.toString(), is(testData)); + assertEquals(processedInput.toString(), testData); } /** @@ -64,7 +63,7 @@ public class FeedHandlerCompressionTest { } processedInput.append((char)readValue); } - assertThat(processedInput.toString(), is(testData)); + assertEquals(processedInput.toString(), testData); } } diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/FeedHandlerV3Test.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/FeedHandlerV3Test.java index 1fd6425f945..2f4afb0c2a5 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/FeedHandlerV3Test.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/FeedHandlerV3Test.java @@ -30,9 +30,8 @@ import java.io.InputStream; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -47,8 +46,8 @@ public class FeedHandlerV3Test { HttpResponse httpResponse = feedHandlerV3.handle(createRequest(1)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); httpResponse.render(outStream); - assertThat(httpResponse.getContentType(), is("text/plain")); - assertThat(Utf8.toString(outStream.toByteArray()), is("1230 OK message trace\n")); + assertEquals(httpResponse.getContentType(), "text/plain"); + assertEquals(Utf8.toString(outStream.toByteArray()), "1230 OK message trace\n"); } @Test @@ -57,9 +56,9 @@ public class FeedHandlerV3Test { HttpResponse httpResponse = feedHandlerV3.handle(createBrokenRequest()); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); httpResponse.render(outStream); - assertThat(httpResponse.getContentType(), is("text/plain")); - assertThat(Utf8.toString(outStream.toByteArray()), startsWith("1230 ERROR ")); - assertThat(metric.get(MetricNames.PARSE_ERROR), is(1L)); + assertEquals(httpResponse.getContentType(), "text/plain"); + assertTrue(Utf8.toString(outStream.toByteArray()).startsWith("1230 ERROR ")); + assertEquals(1L, metric.get(MetricNames.PARSE_ERROR)); } @Test @@ -68,9 +67,9 @@ public class FeedHandlerV3Test { HttpResponse httpResponse = feedHandlerV3.handle(createRequest(100)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); httpResponse.render(outStream); - assertThat(httpResponse.getContentType(), is("text/plain")); + assertEquals(httpResponse.getContentType(), "text/plain"); String result = Utf8.toString(outStream.toByteArray()); - assertThat(Splitter.on("\n").splitToList(result).size(), is(101)); + assertEquals(101, Splitter.on("\n").splitToList(result).size()); } private static DocumentTypeManager createDoctypeManager() { diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/VersionsTestCase.java b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/VersionsTestCase.java index a13f4f79ca9..6858c4bede3 100644 --- a/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/VersionsTestCase.java +++ b/vespaclient-container-plugin/src/test/java/com/yahoo/vespa/http/server/VersionsTestCase.java @@ -10,10 +10,9 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -34,86 +33,86 @@ public class VersionsTestCase { private static final List<String> GARBAGE = Collections.singletonList("garbage"); @Test - public void testEmpty() throws Exception { + public void testEmpty() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(EMPTY); - assertThat(v.first, instanceOf(ErrorHttpResponse.class)); - assertThat(v.second, is(-1)); + assertTrue(v.first instanceof ErrorHttpResponse); + assertEquals(Integer.valueOf(-1), v.second); } @Test - public void testOneTwo() throws Exception { + public void testOneTwo() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_TWO); - assertThat(v.first, instanceOf(ErrorHttpResponse.class)); - assertThat(v.second, is(-1)); + assertTrue(v.first instanceof ErrorHttpResponse); + assertEquals(Integer.valueOf(-1), v.second); } @Test - public void testOneThree() throws Exception { + public void testOneThree() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_THREE); - assertThat(v.first, nullValue()); - assertThat(v.second, is(3)); + assertNull(v.first); + assertEquals(Integer.valueOf(3), v.second); } @Test - public void testTwoThree() throws Exception { + public void testTwoThree() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(TWO_THREE); - assertThat(v.first, nullValue()); - assertThat(v.second, is(3)); + assertNull(v.first); + assertEquals(Integer.valueOf(3), v.second); } @Test - public void testOneNullThree() throws Exception { + public void testOneNullThree() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_NULL_THREE); - assertThat(v.first, nullValue()); - assertThat(v.second, is(3)); + assertNull(v.first); + assertEquals(Integer.valueOf(3), v.second); } @Test - public void testOneCommaThree() throws Exception { + public void testOneCommaThree() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_COMMA_THREE); - assertThat(v.first, nullValue()); - assertThat(v.second, is(3)); + assertNull(v.first); + assertEquals(Integer.valueOf(3), v.second); } @Test - public void testOneEmptyThree() throws Exception { + public void testOneEmptyThree() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(ONE_EMPTY_THREE); - assertThat(v.first, nullValue()); - assertThat(v.second, is(3)); + assertNull(v.first); + assertEquals(Integer.valueOf(3), v.second); } @Test public void testTooLarge() throws Exception { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(TOO_LARGE_NUMBER); - assertThat(v.first, instanceOf(ErrorHttpResponse.class)); + assertTrue(v.first instanceof ErrorHttpResponse); ByteArrayOutputStream errorMsg = new ByteArrayOutputStream(); ErrorHttpResponse errorResponse = (ErrorHttpResponse) v.first; errorResponse.render(errorMsg); - assertThat(errorMsg.toString(), - is("Could not parse X-Yahoo-Feed-Protocol-Versionheader of request (values: [1000000000]). " + - "Server supports protocol versions [3]")); - assertThat(v.second, is(-1)); + assertEquals(errorMsg.toString(), + "Could not parse X-Yahoo-Feed-Protocol-Versionheader of request (values: [1000000000]). " + + "Server supports protocol versions [3]"); + assertEquals(Integer.valueOf(-1), v.second); } @Test - public void testThreeTooLarge() throws Exception { + public void testThreeTooLarge() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(THREE_TOO_LARGE_NUMBER); - assertThat(v.first, nullValue()); - assertThat(v.second, is(3)); + assertNull(v.first); + assertEquals(Integer.valueOf(3), v.second); } @Test - public void testTwoCommaTooLarge() throws Exception { + public void testTwoCommaTooLarge() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(THREE_COMMA_TOO_LARGE_NUMBER); - assertThat(v.first, nullValue()); - assertThat(v.second, is(3)); + assertNull(v.first); + assertEquals(Integer.valueOf(3), v.second); } @Test - public void testGarbage() throws Exception { + public void testGarbage() { Tuple2<HttpResponse, Integer> v = FeedHandler.doCheckProtocolVersion(GARBAGE); - assertThat(v.first, instanceOf(ErrorHttpResponse.class)); - assertThat(v.second, is(-1)); + assertTrue(v.first instanceof ErrorHttpResponse); + assertEquals(Integer.valueOf(-1), v.second); } } |