diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-08-11 23:29:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-11 23:29:08 +0200 |
commit | 5858a6cdae398b95360c5d031e56037799930895 (patch) | |
tree | 737668034aeebf3146b0e2d9229157101c116672 /documentapi | |
parent | a9775442179fd17067cd351051d803920c0d74fc (diff) |
Revert "Reduce the use of hamcrest when normal assertEquals/assertTrue does a…"
Diffstat (limited to 'documentapi')
-rw-r--r-- | documentapi/src/test/java/com/yahoo/documentapi/VisitorDataQueueTest.java | 25 | ||||
-rw-r--r-- | documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/ReplyMergerTestCase.java | 72 |
2 files changed, 47 insertions, 50 deletions
diff --git a/documentapi/src/test/java/com/yahoo/documentapi/VisitorDataQueueTest.java b/documentapi/src/test/java/com/yahoo/documentapi/VisitorDataQueueTest.java index 93e7b2cf309..7cd8cf05c8e 100644 --- a/documentapi/src/test/java/com/yahoo/documentapi/VisitorDataQueueTest.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/VisitorDataQueueTest.java @@ -13,11 +13,12 @@ import com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.core.IsNull.notNullValue; +import static org.hamcrest.core.IsNull.nullValue; +import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; public class VisitorDataQueueTest { @@ -41,14 +42,14 @@ public class VisitorDataQueueTest { } private static void assertNonNullDocumentOpResponse(final VisitorResponse response) { - assertNotNull(response); - assertTrue(response instanceof DocumentOpVisitorResponse); + assertThat(response, notNullValue()); + assertThat(response, instanceOf(DocumentOpVisitorResponse.class)); } private static void assertResponseHasSinglePut(final VisitorResponse response, final DocumentPut expectedInstance) { assertNonNullDocumentOpResponse(response); final DocumentOpVisitorResponse visitorResponse = (DocumentOpVisitorResponse)response; - assertSame(expectedInstance, visitorResponse.getDocumentOperation()); + assertThat(visitorResponse.getDocumentOperation(), is(expectedInstance)); } @Test @@ -59,7 +60,7 @@ public class VisitorDataQueueTest { final VisitorResponse response = queue.getNext(); assertResponseHasSinglePut(response, putMessage.getDocumentPut()); - assertNull(queue.getNext()); // Queue now empty + assertThat(queue.getNext(), nullValue()); // Queue now empty } @Test @@ -70,14 +71,14 @@ public class VisitorDataQueueTest { final VisitorResponse response = queue.getNext(1000); assertResponseHasSinglePut(response, putMessage.getDocumentPut()); - assertNull(queue.getNext()); // Queue now empty + assertThat(queue.getNext(), nullValue()); // Queue now empty } private static void assertResponseHasSingleRemove(final VisitorResponse response, final String docId) { assertNonNullDocumentOpResponse(response); final DocumentOpVisitorResponse visitorResponse = (DocumentOpVisitorResponse)response; - assertTrue(visitorResponse.getDocumentOperation() instanceof DocumentRemove); - assertEquals(new DocumentId(docId), visitorResponse.getDocumentOperation().getId()); + assertThat(visitorResponse.getDocumentOperation(), instanceOf(DocumentRemove.class)); + assertThat(visitorResponse.getDocumentOperation().getId(), equalTo(new DocumentId(docId))); } @Test diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/ReplyMergerTestCase.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/ReplyMergerTestCase.java index 9172752760d..7f0ede0db70 100644 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/ReplyMergerTestCase.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/ReplyMergerTestCase.java @@ -2,18 +2,14 @@ package com.yahoo.documentapi.messagebus.protocol; import com.yahoo.collections.Tuple2; -import com.yahoo.messagebus.EmptyReply; +import com.yahoo.messagebus.*; import com.yahoo.messagebus.Error; -import com.yahoo.messagebus.Reply; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - +@SuppressWarnings("deprecation") public class ReplyMergerTestCase { private ReplyMerger merger; @@ -33,8 +29,8 @@ public class ReplyMergerTestCase { merger.merge(2, r3); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertEquals(0, ret.first.intValue()); - assertSame(r1, ret.second); + assertThat(ret.first, is(0)); + assertThat(ret.second, sameInstance(r1)); } @Test @@ -45,8 +41,8 @@ public class ReplyMergerTestCase { merger.merge(0, r1); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertNull(ret.first); - assertNotSame(r1, ret.second); + assertThat(ret.first, nullValue()); + assertThat(ret.second, not(sameInstance(r1))); assertThatErrorsMatch(new Error[] { error }, ret); } @@ -61,8 +57,8 @@ public class ReplyMergerTestCase { merger.merge(0, r1); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertNull(ret.first); - assertNotSame(r1, ret.second); + assertThat(ret.first, nullValue()); + assertThat(ret.second, not(sameInstance(r1))); assertThatErrorsMatch(errors, ret); } @@ -80,9 +76,9 @@ public class ReplyMergerTestCase { merger.merge(1, r2); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertNull(ret.first); - assertNotSame(r1, ret.second); - assertNotSame(r2, ret.second); + assertThat(ret.first, nullValue()); + assertThat(ret.second, not(sameInstance(r1))); + assertThat(ret.second, not(sameInstance(r2))); assertThatErrorsMatch(errors, ret); } @@ -102,9 +98,9 @@ public class ReplyMergerTestCase { merger.merge(0, r1); merger.merge(1, r2); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertNull(ret.first); - assertNotSame(r1, ret.second); - assertNotSame(r2, ret.second); + assertThat(ret.first, nullValue()); + assertThat(ret.second, not(sameInstance(r1))); + assertThat(ret.second, not(sameInstance(r2))); // Only first ignore error from each reply assertThatErrorsMatch(new Error[]{ errors[0], errors[2] }, ret); } @@ -120,8 +116,8 @@ public class ReplyMergerTestCase { merger.merge(0, r1); merger.merge(1, r2); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertEquals(1, ret.first.intValue()); - assertSame(r2, ret.second); + assertThat(ret.first, is(1)); + assertThat(ret.second, sameInstance(r2)); // Only first ignore error from each reply assertThatErrorsMatch(new Error[]{ }, ret); } @@ -142,9 +138,9 @@ public class ReplyMergerTestCase { merger.merge(0, r1); merger.merge(1, r2); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertNull(ret.first); - assertNotSame(r1, ret.second); - assertNotSame(r2, ret.second); + assertThat(ret.first, nullValue()); + assertThat(ret.second, not(sameInstance(r1))); + assertThat(ret.second, not(sameInstance(r2))); // All errors from replies with errors are included, not those that // are fully ignored. assertThatErrorsMatch(new Error[]{ errors[0], errors[1] }, ret); @@ -163,8 +159,8 @@ public class ReplyMergerTestCase { merger.merge(1, r2); merger.merge(2, r3); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertEquals(1, ret.first.intValue()); - assertSame(r2, ret.second); + assertThat(ret.first, is(1)); + assertThat(ret.second, sameInstance((Reply) r2)); } @Test @@ -177,8 +173,8 @@ public class ReplyMergerTestCase { merger.merge(0, r1); merger.merge(1, r2); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertEquals(0, ret.first.intValue()); - assertSame(r1, ret.second); + assertThat(ret.first, is(0)); + assertThat(ret.second, sameInstance((Reply)r1)); } @Test @@ -194,8 +190,8 @@ public class ReplyMergerTestCase { merger.merge(1, r2); merger.merge(2, r3); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertEquals(1, ret.first.intValue()); - assertSame(r2, ret.second); + assertThat(ret.first, is(1)); + assertThat(ret.second, sameInstance((Reply)r2)); } @Test @@ -209,23 +205,23 @@ public class ReplyMergerTestCase { merger.merge(1, r2); merger.merge(2, r3); Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertEquals(1, ret.first.intValue()); - assertSame(r2, ret.second); + assertThat(ret.first, is(1)); + assertThat(ret.second, sameInstance((Reply)r2)); } @Test public void mergingZeroRepliesReturnsDefaultEmptyReply() { Tuple2<Integer, Reply> ret = merger.mergedReply(); - assertNull(ret.first); - assertTrue(ret.second instanceof EmptyReply); + assertThat(ret.first, nullValue()); + assertThat(ret.second, instanceOf(EmptyReply.class)); assertThatErrorsMatch(new Error[]{}, ret); } private void assertThatErrorsMatch(Error[] errors, Tuple2<Integer, Reply> ret) { - assertEquals(errors.length, ret.second.getNumErrors()); + assertThat(ret.second.getNumErrors(), is(errors.length)); for (int i = 0; i < ret.second.getNumErrors(); ++i) { - assertEquals(errors[i].getCode(), ret.second.getError(i).getCode()); - assertEquals(errors[i].getMessage(), ret.second.getError(i).getMessage()); + assertThat(ret.second.getError(i).getCode(), is(errors[i].getCode())); + assertThat(ret.second.getError(i).getMessage(), is(errors[i].getMessage())); } } |