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