diff options
33 files changed, 388 insertions, 385 deletions
diff --git a/chain/pom.xml b/chain/pom.xml index 67ee1a4c0e7..2ead24a89b7 100755 --- a/chain/pom.xml +++ b/chain/pom.xml @@ -26,6 +26,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>com.yahoo.vespa</groupId> <artifactId>provided-dependencies</artifactId> <version>${project.version}</version> diff --git a/chain/src/test/java/com/yahoo/component/chain/model/ChainsModelBuilderTest.java b/chain/src/test/java/com/yahoo/component/chain/model/ChainsModelBuilderTest.java index 7cef03bbb06..2a22b5afbf7 100644 --- a/chain/src/test/java/com/yahoo/component/chain/model/ChainsModelBuilderTest.java +++ b/chain/src/test/java/com/yahoo/component/chain/model/ChainsModelBuilderTest.java @@ -11,7 +11,8 @@ import java.util.Set; import static com.yahoo.container.core.ChainsConfig.Components; import static com.yahoo.container.core.ChainsConfig.Chains; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** @@ -22,7 +23,7 @@ public class ChainsModelBuilderTest { @Test public void components_are_added_to_componentModels() throws Exception { ChainsModel model = chainsModel(); - assertEquals(2, model.allComponents().size()); + assertThat(model.allComponents().size(), is(2)); assertTrue(model.componentModels().containsKey(new ComponentId("componentA"))); } @@ -37,7 +38,7 @@ public class ChainsModelBuilderTest { public void inherited_chains_are_added_to_chainSpecification() throws Exception { ChainsModel model = chainsModel(); ChainSpecification inheritsChain1 = model.chainSpecifications().get(new ComponentId("inheritsChain1")).model(); - assertEquals(2, model.allChainsFlattened().size()); + assertThat(model.allChainsFlattened().size(), is(2)); assertTrue(getComponentsByName(inheritsChain1.inheritance.chainSpecifications).containsKey("chain1")); assertTrue(getComponentsByName(inheritsChain1.inheritance.excludedComponents).containsKey("componentA")); } diff --git a/config-model-api/src/test/java/com/yahoo/config/application/api/ApplicationFileTest.java b/config-model-api/src/test/java/com/yahoo/config/application/api/ApplicationFileTest.java index 6a305f9979e..5b0b11b88b7 100644 --- a/config-model-api/src/test/java/com/yahoo/config/application/api/ApplicationFileTest.java +++ b/config-model-api/src/test/java/com/yahoo/config/application/api/ApplicationFileTest.java @@ -12,10 +12,12 @@ import java.io.IOException; import java.io.StringReader; import java.util.List; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** @@ -57,8 +59,8 @@ public abstract class ApplicationFileTest { Path p1 = Path.fromString("foo/bar/baz"); ApplicationFile f1 = getApplicationFile(p1); ApplicationFile f2 = getApplicationFile(p1); - assertEquals(p1, f1.getPath()); - assertEquals(p1, f2.getPath()); + assertThat(f1.getPath(), is(p1)); + assertThat(f2.getPath(), is(p1)); } @Test @@ -132,7 +134,7 @@ public abstract class ApplicationFileTest { file.writeFile(new StringReader("foobar")); assertTrue(file.exists()); assertFalse(file.isDirectory()); - assertEquals("foobar", com.yahoo.io.IOUtils.readAll(file.createReader())); + assertThat(com.yahoo.io.IOUtils.readAll(file.createReader()), is("foobar")); } @Test @@ -142,7 +144,7 @@ public abstract class ApplicationFileTest { file.writeFile(new StringReader("foobar")); assertTrue(file.exists()); assertFalse(file.isDirectory()); - assertEquals("foobar", com.yahoo.io.IOUtils.readAll(file.createReader())); + assertThat(com.yahoo.io.IOUtils.readAll(file.createReader()), is("foobar")); } @Test @@ -151,7 +153,7 @@ public abstract class ApplicationFileTest { assertTrue(file.exists()); assertTrue(file.isDirectory()); List<ApplicationFile> list = file.listFiles(); - assertEquals(6, list.size()); + assertThat(list.size(), is(6)); assertTrue(listContains(list, "vespa-services.xml")); assertTrue(listContains(list, "vespa-hosts.xml")); assertTrue(listContains(list, "components/")); @@ -173,7 +175,7 @@ public abstract class ApplicationFileTest { assertTrue(listContains(list, "components/file.txt")); list = getApplicationFile(Path.fromString("templates")).listFiles(true); - assertEquals(14, list.size()); + assertThat(list.size(), is(14)); assertTrue(listContains(list, "templates/basic/")); assertTrue(listContains(list, "templates/basic/error.templ")); assertTrue(listContains(list, "templates/basic/header.templ")); @@ -209,7 +211,7 @@ public abstract class ApplicationFileTest { return path.getName().endsWith(".xml"); } }); - assertEquals(2, list.size()); + assertThat(list.size(), is(2)); assertFalse(listContains(list, "components/")); assertFalse(listContains(list, "files/")); assertFalse(listContains(list, "searchdefinitions/")); @@ -235,7 +237,7 @@ public abstract class ApplicationFileTest { public void testApplicationFileCanBeDeleted() throws Exception { ApplicationFile file = getApplicationFile(Path.fromString("file1.txt")); file.writeFile(new StringReader("file1")); - assertEquals("file1.txt", file.getPath().getName()); + assertThat(file.getPath().getName(), is("file1.txt")); file.delete(); assertFalse(file.exists()); assertFalse(file.isDirectory()); @@ -244,7 +246,7 @@ public abstract class ApplicationFileTest { file = getApplicationFile(Path.fromString("subdir/file2.txt")); file.writeFile(new StringReader("file2")); - assertEquals("file2.txt", file.getPath().getName()); + assertThat(file.getPath().getName(), is("file2.txt")); file.delete(); assertFalse(file.exists()); assertFalse(file.isDirectory()); @@ -255,48 +257,48 @@ public abstract class ApplicationFileTest { @Test public void getGetMetaPath() throws Exception { ApplicationFile file = getApplicationFile(Path.fromString("file1.txt")); - assertEquals(".meta/file1.txt", file.getMetaPath().toString()); + assertThat(file.getMetaPath().toString(), is(".meta/file1.txt")); file = getApplicationFile(Path.fromString("dir/file1.txt")); - assertEquals("dir/.meta/file1.txt", file.getMetaPath().toString()); + assertThat(file.getMetaPath().toString(), is("dir/.meta/file1.txt")); file = getApplicationFile(Path.fromString("dir")); - assertEquals(".meta/dir", file.getMetaPath().toString()); + assertThat(file.getMetaPath().toString(), is(".meta/dir")); file = getApplicationFile(Path.fromString("")); - assertEquals(".meta/.root", file.getMetaPath().toString()); + assertThat(file.getMetaPath().toString(), is(".meta/.root")); } @Test public void getGetMetaContent() throws Exception { String testFileName = "file1.txt"; ApplicationFile file = getApplicationFile(Path.fromString(testFileName)); - assertEquals(".meta/" + testFileName, file.getMetaPath().toString()); + assertThat(file.getMetaPath().toString(), is(".meta/" + testFileName)); String input = "a"; file.writeFile(new StringReader(input)); - assertEquals(ApplicationFile.ContentStatusNew, file.getMetaData().getStatus()); - assertEquals(ConfigUtils.getMd5(input), file.getMetaData().getMd5()); + assertThat(file.getMetaData().getStatus(), is(ApplicationFile.ContentStatusNew)); + assertThat(file.getMetaData().getMd5(), is(ConfigUtils.getMd5(input))); testFileName = "foo"; ApplicationFile fooDir = getApplicationFile(Path.fromString(testFileName)); fooDir.createDirectory(); - assertEquals(ApplicationFile.ContentStatusNew, fooDir.getMetaData().getStatus()); - assertTrue(fooDir.getMetaData().getMd5().isEmpty()); + assertThat(fooDir.getMetaData().getStatus(), is(ApplicationFile.ContentStatusNew)); + assertThat(fooDir.getMetaData().getMd5(), is("")); testFileName = "foo/file2.txt"; file = getApplicationFile(Path.fromString(testFileName)); input = "a"; file.writeFile(new StringReader(input)); - assertEquals(ApplicationFile.ContentStatusNew, file.getMetaData().getStatus()); - assertEquals(ConfigUtils.getMd5(input), file.getMetaData().getMd5()); + assertThat(file.getMetaData().getStatus(), is(ApplicationFile.ContentStatusNew)); + assertThat(file.getMetaData().getMd5(), is(ConfigUtils.getMd5(input))); file.delete(); - assertEquals(ApplicationFile.ContentStatusDeleted, file.getMetaData().getStatus()); - assertTrue(file.getMetaData().getMd5().isEmpty()); + assertThat(file.getMetaData().getStatus(), is(ApplicationFile.ContentStatusDeleted)); + assertThat(file.getMetaData().getMd5(), is("")); fooDir.delete(); - assertEquals(ApplicationFile.ContentStatusDeleted, fooDir.getMetaData().getStatus()); - assertTrue(file.getMetaData().getMd5().isEmpty()); + assertThat(fooDir.getMetaData().getStatus(), is(ApplicationFile.ContentStatusDeleted)); + assertThat(file.getMetaData().getMd5(), is("")); // non-existing file testFileName = "non-existing"; @@ -318,7 +320,7 @@ public abstract class ApplicationFileTest { private void assertFileContent(String expected, String path) throws Exception { ApplicationFile file = getApplicationFile(Path.fromString(path)); String actual = com.yahoo.io.IOUtils.readAll(file.createReader()); - assertEquals(expected, actual); + assertThat(actual, is(expected)); } public abstract ApplicationFile getApplicationFile(Path path) throws Exception; diff --git a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MbusRequestContext.java b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MbusRequestContext.java index 09d25f60835..a9bd63d96c3 100644 --- a/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MbusRequestContext.java +++ b/docproc/src/main/java/com/yahoo/docproc/jdisc/messagebus/MbusRequestContext.java @@ -24,6 +24,7 @@ import com.yahoo.messagebus.Message; import com.yahoo.messagebus.Reply; import com.yahoo.messagebus.jdisc.MbusRequest; import com.yahoo.messagebus.jdisc.MbusResponse; +import com.yahoo.messagebus.routing.Route; import java.net.URI; import java.util.ArrayList; diff --git a/docproc/src/test/java/com/yahoo/docproc/ProcessingTestCase.java b/docproc/src/test/java/com/yahoo/docproc/ProcessingTestCase.java index e72b9d991b6..8d3e387a0c5 100644 --- a/docproc/src/test/java/com/yahoo/docproc/ProcessingTestCase.java +++ b/docproc/src/test/java/com/yahoo/docproc/ProcessingTestCase.java @@ -7,10 +7,8 @@ import org.junit.Test; import java.util.Iterator; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -20,8 +18,8 @@ public class ProcessingTestCase { @Test public void serviceName() { - assertEquals("default", new Processing().getServiceName()); - assertEquals("foobar", new Processing("foobar", (DocumentOperation) null, null).getServiceName()); + assertThat(new Processing().getServiceName(), is("default")); + assertThat(new Processing("foobar", (DocumentOperation) null, null).getServiceName(), is("foobar")); } @Test @@ -32,21 +30,21 @@ public class ProcessingTestCase { p.setVariable("bar", "apple"); Iterator<Map.Entry<String, Object>> it = p.getVariableAndNameIterator(); - assertTrue(it.hasNext()); - assertNotNull(it.next()); - assertTrue(it.hasNext()); - assertNotNull(it.next()); - assertFalse(it.hasNext()); + assertThat(it.hasNext(), is(true)); + assertThat(it.next(), not(nullValue())); + assertThat(it.hasNext(), is(true)); + assertThat(it.next(), not(nullValue())); + assertThat(it.hasNext(), is(false)); - assertTrue(p.hasVariable("foo")); - assertTrue(p.hasVariable("bar")); - assertFalse(p.hasVariable("baz")); + assertThat(p.hasVariable("foo"), is(true)); + assertThat(p.hasVariable("bar"), is(true)); + assertThat(p.hasVariable("baz"), is(false)); - assertEquals("banana", p.removeVariable("foo")); + assertThat(p.removeVariable("foo"), is("banana")); p.clearVariables(); it = p.getVariableAndNameIterator(); - assertFalse(it.hasNext()); + assertThat(it.hasNext(), is(false)); } } diff --git a/docproc/src/test/java/com/yahoo/docproc/SimpleDocumentProcessorTestCase.java b/docproc/src/test/java/com/yahoo/docproc/SimpleDocumentProcessorTestCase.java index 741d10bdc43..c89ac21610e 100644 --- a/docproc/src/test/java/com/yahoo/docproc/SimpleDocumentProcessorTestCase.java +++ b/docproc/src/test/java/com/yahoo/docproc/SimpleDocumentProcessorTestCase.java @@ -15,9 +15,9 @@ import com.yahoo.document.idstring.IdIdString; import com.yahoo.statistics.StatisticsImpl; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.nullValue; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -60,12 +60,14 @@ public class SimpleDocumentProcessorTestCase { DocprocService service = setupDocprocService(new VerySimpleDocumentProcessor()); service.getExecutor().process(p); - assertEquals(3, p.getDocumentOperations().size()); - assertTrue(p.getDocumentOperations().get(0) instanceof DocumentPut); - assertEquals("processed", ((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue()); - assertTrue(p.getDocumentOperations().get(1) instanceof DocumentUpdate); - assertTrue(p.getDocumentOperations().get(2) instanceof DocumentRemove); - assertEquals("id:foobar:foobar::12345", p.getDocumentOperations().get(2).getId().toString()); + assertThat(p.getDocumentOperations().size(), is(3)); + assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true)); + assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), + is("processed")); + assertThat(p.getDocumentOperations().get(1) instanceof DocumentUpdate, is(true)); + assertThat(p.getDocumentOperations().get(2) instanceof DocumentRemove, is(true)); + assertThat(p.getDocumentOperations().get(2).getId().toString(), + is("id:foobar:foobar::12345")); } @Test @@ -76,9 +78,10 @@ public class SimpleDocumentProcessorTestCase { DocprocService service = setupDocprocService(new VerySimpleDocumentProcessor()); service.getExecutor().process(p); - assertEquals(1, p.getDocumentOperations().size()); - assertTrue(p.getDocumentOperations().get(0) instanceof DocumentPut); - assertEquals("processed", ((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue()); + assertThat(p.getDocumentOperations().size(), is(1)); + assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true)); + assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), + is("processed")); } @Test @@ -96,13 +99,16 @@ public class SimpleDocumentProcessorTestCase { //ok } - assertEquals(3, p.getDocumentOperations().size()); - assertTrue(p.getDocumentOperations().get(0) instanceof DocumentPut); - assertEquals("processed", ((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue()); - assertTrue(p.getDocumentOperations().get(1) instanceof DocumentRemove); - assertEquals("id:this:foobar::is:a:remove", p.getDocumentOperations().get(1).getId().toString()); - assertTrue(p.getDocumentOperations().get(2) instanceof DocumentPut); - assertNull(((DocumentPut) p.getDocumentOperations().get(2)).getDocument().getFieldValue("title")); + assertThat(p.getDocumentOperations().size(), is(3)); + assertThat(p.getDocumentOperations().get(0) instanceof DocumentPut, is(true)); + assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument().getFieldValue("title").getWrappedValue(), + is("processed")); + assertThat(p.getDocumentOperations().get(1) instanceof DocumentRemove, is(true)); + assertThat(p.getDocumentOperations().get(1).getId().toString(), + is("id:this:foobar::is:a:remove")); + assertThat(p.getDocumentOperations().get(2) instanceof DocumentPut, is(true)); + assertThat(((DocumentPut) p.getDocumentOperations().get(2)).getDocument().getFieldValue("title"), + nullValue()); } diff --git a/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerAllMessageTypesTestCase.java b/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerAllMessageTypesTestCase.java index c508e7da61d..5893013a187 100644 --- a/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerAllMessageTypesTestCase.java +++ b/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerAllMessageTypesTestCase.java @@ -30,10 +30,12 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -70,7 +72,7 @@ public class DocumentProcessingHandlerAllMessageTypesTestCase extends DocumentPr Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS); assertNotNull(reply); - assertTrue(result instanceof GetDocumentMessage); + assertThat(result, instanceOf(GetDocumentMessage.class)); assertFalse(reply.hasErrors()); } @@ -89,9 +91,9 @@ public class DocumentProcessingHandlerAllMessageTypesTestCase extends DocumentPr Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS); assertNotNull(reply); - assertTrue(result instanceof PutDocumentMessage); + assertThat(result, instanceOf(PutDocumentMessage.class)); PutDocumentMessage outputMsg = (PutDocumentMessage) result; - assertEquals("THIS IS A TEST.", ((StringFieldValue) outputMsg.getDocumentPut().getDocument().getFieldValue("blahblah")).getString()); + assertThat(((StringFieldValue) outputMsg.getDocumentPut().getDocument().getFieldValue("blahblah")).getString(), is("THIS IS A TEST.")); assertFalse(reply.hasErrors()); } @@ -107,9 +109,9 @@ public class DocumentProcessingHandlerAllMessageTypesTestCase extends DocumentPr Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS); assertNotNull(reply); - assertTrue(result instanceof RemoveDocumentMessage); + assertThat(result, instanceOf(RemoveDocumentMessage.class)); RemoveDocumentMessage outputMsg = (RemoveDocumentMessage) result; - assertEquals("id:ns:baz::12345:6789", outputMsg.getDocumentId().toString()); + assertThat(outputMsg.getDocumentId().toString(), is("id:ns:baz::12345:6789")); assertFalse(reply.hasErrors()); } @@ -126,9 +128,9 @@ public class DocumentProcessingHandlerAllMessageTypesTestCase extends DocumentPr Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS); assertNotNull(reply); - assertTrue(result instanceof UpdateDocumentMessage); + assertThat(result, instanceOf(UpdateDocumentMessage.class)); UpdateDocumentMessage outputMsg = (UpdateDocumentMessage) result; - assertEquals("id:ns:baz::foo", outputMsg.getDocumentUpdate().getId().toString()); + assertThat(outputMsg.getDocumentUpdate().getId().toString(), is("id:ns:baz::foo")); assertFalse(reply.hasErrors()); } diff --git a/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerBasicTestCase.java b/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerBasicTestCase.java index 9dc0b2a38f5..01b66bc2fb6 100644 --- a/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerBasicTestCase.java +++ b/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerBasicTestCase.java @@ -19,9 +19,11 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** @@ -49,11 +51,11 @@ public class DocumentProcessingHandlerBasicTestCase extends DocumentProcessingHa Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS); assertNotNull(reply); - assertTrue((msg instanceof PutDocumentMessage)); + assertThat((msg instanceof PutDocumentMessage), is(true)); PutDocumentMessage put = (PutDocumentMessage) msg; Document outDoc = put.getDocumentPut().getDocument(); - assertEquals(document, outDoc); + assertThat(document, equalTo(outDoc)); assertFalse(reply.hasErrors()); } diff --git a/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerTestBase.java b/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerTestBase.java index f15b505d05f..df3224827ef 100644 --- a/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerTestBase.java +++ b/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerTestBase.java @@ -7,8 +7,10 @@ import com.yahoo.component.provider.ComponentRegistry; import com.yahoo.container.core.document.ContainerDocumentConfig; import com.yahoo.container.jdisc.messagebus.MbusServerProvider; import com.yahoo.container.jdisc.messagebus.SessionCache; +import com.yahoo.docproc.AbstractConcreteDocumentFactory; import com.yahoo.docproc.CallStack; import com.yahoo.docproc.DocprocService; +import com.yahoo.docproc.DocumentProcessor; import com.yahoo.docproc.jdisc.messagebus.MbusRequestContext; import com.yahoo.document.DocumentType; diff --git a/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerTransformingMessagesTestCase.java b/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerTransformingMessagesTestCase.java index 01ea5fd2fc9..00efab737c4 100644 --- a/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerTransformingMessagesTestCase.java +++ b/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerTransformingMessagesTestCase.java @@ -29,10 +29,9 @@ import java.util.List; import java.util.ListIterator; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -86,30 +85,30 @@ public class DocumentProcessingHandlerTransformingMessagesTestCase extends Docum { PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(new Document(getType(), "id:nodocstatus:foo::put:to:put"))); Routable result = sendMessageAndGetResult(message); - assertTrue(result instanceof PutDocumentMessage); + assertThat(result, instanceOf(PutDocumentMessage.class)); PutDocumentMessage outputMsg = (PutDocumentMessage)result; - assertEquals("banana", outputMsg.getDocumentPut().getDocument().getFieldValue("foostring").toString()); + assertThat(outputMsg.getDocumentPut().getDocument().getFieldValue("foostring").toString(), is("banana")); } { PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(new Document(getType(), "id:nodocstatus:foo::put:to:remove"))); Routable result = sendMessageAndGetResult(message); - assertTrue(result instanceof RemoveDocumentMessage); + assertThat(result, instanceOf(RemoveDocumentMessage.class)); RemoveDocumentMessage outputMsg = (RemoveDocumentMessage)result; - assertEquals("id:nodocstatus:foo::put:to:remove", outputMsg.getDocumentId().toString()); + assertThat(outputMsg.getDocumentId().toString(), is("id:nodocstatus:foo::put:to:remove")); } { PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(new Document(getType(), "id:nodocstatus:foo::put:to:update"))); Routable result = sendMessageAndGetResult(message); - assertTrue(result instanceof UpdateDocumentMessage); + assertThat(result, instanceOf(UpdateDocumentMessage.class)); UpdateDocumentMessage outputMsg = (UpdateDocumentMessage)result; - assertEquals("id:nodocstatus:foo::put:to:update", outputMsg.getDocumentUpdate().getId().toString()); + assertThat(outputMsg.getDocumentUpdate().getId().toString(), is("id:nodocstatus:foo::put:to:update")); } { PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(new Document(getType(), "id:nodocstatus:foo::put:to:nothing"))); assertTrue(sendMessage(FOOBAR, message)); Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS); assertNotNull(reply); - assertTrue(reply instanceof DocumentReply); + assertThat(reply, instanceOf(DocumentReply.class)); assertFalse(reply.hasErrors()); } } @@ -118,31 +117,31 @@ public class DocumentProcessingHandlerTransformingMessagesTestCase extends Docum { RemoveDocumentMessage message = new RemoveDocumentMessage(new DocumentId("id:nodocstatus:foo::remove:to:put")); Routable result = sendMessageAndGetResult(message); - assertTrue(result instanceof PutDocumentMessage); + assertThat(result, instanceOf(PutDocumentMessage.class)); PutDocumentMessage outputMsg = (PutDocumentMessage)result; - assertEquals("id:nodocstatus:foo::remove:to:put", outputMsg.getDocumentPut().getDocument().getId().toString()); + assertThat(outputMsg.getDocumentPut().getDocument().getId().toString(), is("id:nodocstatus:foo::remove:to:put")); } { RemoveDocumentMessage message = new RemoveDocumentMessage(new DocumentId("id:nodocstatus:foo::remove:to:remove")); Routable result = sendMessageAndGetResult(message); - assertTrue(result instanceof RemoveDocumentMessage); + assertThat(result, instanceOf(RemoveDocumentMessage.class)); RemoveDocumentMessage outputMsg = (RemoveDocumentMessage)result; - assertEquals("id:nodocstatus:foo::remove:to:remove", outputMsg.getDocumentId().toString()); + assertThat(outputMsg.getDocumentId().toString(), is("id:nodocstatus:foo::remove:to:remove")); } { RemoveDocumentMessage message = new RemoveDocumentMessage(new DocumentId("id:nodocstatus:foo::remove:to:update")); Routable result = sendMessageAndGetResult(message); - assertTrue(result instanceof UpdateDocumentMessage); + assertThat(result, instanceOf(UpdateDocumentMessage.class)); UpdateDocumentMessage outputMsg = (UpdateDocumentMessage)result; - assertEquals("id:nodocstatus:foo::remove:to:update", outputMsg.getDocumentUpdate().getId().toString()); + assertThat(outputMsg.getDocumentUpdate().getId().toString(), is("id:nodocstatus:foo::remove:to:update")); } { RemoveDocumentMessage message = new RemoveDocumentMessage(new DocumentId("id:nodocstatus:foo::remove:to:nothing")); assertTrue(sendMessage(FOOBAR, message)); Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS); assertNotNull(reply); - assertTrue(reply instanceof DocumentReply); + assertThat(reply, instanceOf(DocumentReply.class)); assertFalse(reply.hasErrors()); } } @@ -151,31 +150,31 @@ public class DocumentProcessingHandlerTransformingMessagesTestCase extends Docum { UpdateDocumentMessage message = new UpdateDocumentMessage(new DocumentUpdate(getType(), "id:nodocstatus:foo::update:to:put")); Routable result = sendMessageAndGetResult(message); - assertTrue(result instanceof PutDocumentMessage); + assertThat(result, instanceOf(PutDocumentMessage.class)); PutDocumentMessage outputMsg = (PutDocumentMessage)result; - assertEquals("id:nodocstatus:foo::update:to:put", outputMsg.getDocumentPut().getDocument().getId().toString()); + assertThat(outputMsg.getDocumentPut().getDocument().getId().toString(), is("id:nodocstatus:foo::update:to:put")); } { UpdateDocumentMessage message = new UpdateDocumentMessage(new DocumentUpdate(getType(), "id:nodocstatus:foo::update:to:remove")); Routable result = sendMessageAndGetResult(message); - assertTrue(result instanceof RemoveDocumentMessage); + assertThat(result, instanceOf(RemoveDocumentMessage.class)); RemoveDocumentMessage outputMsg = (RemoveDocumentMessage)result; - assertEquals("id:nodocstatus:foo::update:to:remove", outputMsg.getDocumentId().toString()); + assertThat(outputMsg.getDocumentId().toString(), is("id:nodocstatus:foo::update:to:remove")); } { UpdateDocumentMessage message = new UpdateDocumentMessage(new DocumentUpdate(getType(), "id:nodocstatus:foo::update:to:update")); Routable result = sendMessageAndGetResult(message); - assertTrue(result instanceof UpdateDocumentMessage); + assertThat(result, instanceOf(UpdateDocumentMessage.class)); UpdateDocumentMessage outputMsg = (UpdateDocumentMessage)result; - assertEquals("id:nodocstatus:foo::update:to:update", outputMsg.getDocumentUpdate().getId().toString()); + assertThat(outputMsg.getDocumentUpdate().getId().toString(), is("id:nodocstatus:foo::update:to:update")); } { UpdateDocumentMessage message = new UpdateDocumentMessage(new DocumentUpdate(getType(), "id:nodocstatus:foo::update:to:nothing")); assertTrue(sendMessage(FOOBAR, message)); Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS); assertNotNull(reply); - assertTrue(reply instanceof DocumentReply); + assertThat(reply, instanceOf(DocumentReply.class)); assertFalse(reply.hasErrors()); } } diff --git a/docproc/src/test/java/com/yahoo/docproc/util/SplitterJoinerTestCase.java b/docproc/src/test/java/com/yahoo/docproc/util/SplitterJoinerTestCase.java index aa55d5b6a41..c4f65987692 100644 --- a/docproc/src/test/java/com/yahoo/docproc/util/SplitterJoinerTestCase.java +++ b/docproc/src/test/java/com/yahoo/docproc/util/SplitterJoinerTestCase.java @@ -12,15 +12,17 @@ import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.StringFieldValue; import org.junit.Test; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> */ -@SuppressWarnings({"unchecked"}) +@SuppressWarnings({"unchecked","rawtypes"}) public class SplitterJoinerTestCase { @Test @@ -38,7 +40,7 @@ public class SplitterJoinerTestCase { DocumentTypeManager manager = splitter.manager; - // Create documents + /**** Create documents: ****/ Document inner1 = new Document(manager.getDocumentType("docindoc"), "id:inner:docindoc::one"); inner1.setFieldValue("name", new StringFieldValue("Donald Duck")); @@ -54,17 +56,17 @@ public class SplitterJoinerTestCase { Document outer = new Document(manager.getDocumentType("outerdoc"), "id:outer:outerdoc::the:only:one"); outer.setFieldValue("innerdocuments", innerArray); - // End create documents + /**** End create documents ****/ Processing p = Processing.of(new DocumentPut(outer)); splitter.process(p); assertEquals(2, p.getDocumentOperations().size()); - assertSame(inner1, ((DocumentPut)(p.getDocumentOperations().get(0))).getDocument()); - assertSame(inner2, ((DocumentPut)(p.getDocumentOperations().get(1))).getDocument()); - assertSame(outer, ((DocumentPut)(p.getVariable(cfg.contextFieldName()))).getDocument()); - assertSame(innerArray, outer.getFieldValue("innerdocuments")); + assertThat(((DocumentPut)(p.getDocumentOperations().get(0))).getDocument(), sameInstance(inner1)); + assertThat(((DocumentPut)(p.getDocumentOperations().get(1))).getDocument(), sameInstance(inner2)); + assertThat(((DocumentPut)(p.getVariable(cfg.contextFieldName()))).getDocument(), sameInstance(outer)); + assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray)); assertTrue(innerArray.isEmpty()); @@ -72,13 +74,13 @@ public class SplitterJoinerTestCase { joiner.process(p); - assertEquals(1, p.getDocumentOperations().size()); - assertSame(outer, ((DocumentPut)p.getDocumentOperations().get(0)).getDocument()); - assertNull(p.getVariable(cfg.contextFieldName())); - assertSame(innerArray, outer.getFieldValue("innerdocuments")); - assertEquals(2, innerArray.size()); - assertSame(inner1, innerArray.get(0)); - assertSame(inner2, innerArray.get(1)); + assertThat(p.getDocumentOperations().size(), equalTo(1)); + assertThat(((DocumentPut)p.getDocumentOperations().get(0)).getDocument(), sameInstance(outer)); + assertThat(p.getVariable(cfg.contextFieldName()), nullValue()); + assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray)); + assertThat(innerArray.size(), equalTo(2)); + assertThat(innerArray.get(0), sameInstance(inner1)); + assertThat(innerArray.get(1), sameInstance(inner2)); } } diff --git a/document/src/test/java/com/yahoo/document/DocumentIdTestCase.java b/document/src/test/java/com/yahoo/document/DocumentIdTestCase.java index a0c5da52ff7..fea3b265b6d 100644 --- a/document/src/test/java/com/yahoo/document/DocumentIdTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentIdTestCase.java @@ -16,8 +16,10 @@ import java.io.UnsupportedEncodingException; import java.util.regex.Pattern; import java.util.Arrays; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -225,7 +227,7 @@ public class DocumentIdTestCase { new DocumentId(strId); fail("Expected an IllegalArgumentException to be thrown"); } catch (IllegalArgumentException ex) { - assertTrue(ex.getMessage().contains(exceptionMsg)); + assertThat(ex.getMessage(), containsString(exceptionMsg)); } } @@ -252,7 +254,7 @@ public class DocumentIdTestCase { DocumentId.createFromSerialized(strId); fail("Expected an IllegalArgumentException to be thrown"); } catch (IllegalArgumentException ex) { - assertTrue(ex.getMessage().contains("illegal zero byte code point")); + assertThat(ex.getMessage(), containsString("illegal zero byte code point")); } } diff --git a/document/src/test/java/com/yahoo/document/DocumentRemoveTestCase.java b/document/src/test/java/com/yahoo/document/DocumentRemoveTestCase.java index 31093e8617b..8b84dc5f46b 100644 --- a/document/src/test/java/com/yahoo/document/DocumentRemoveTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentRemoveTestCase.java @@ -3,10 +3,10 @@ package com.yahoo.document; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -18,7 +18,7 @@ public class DocumentRemoveTestCase { public void requireThatToStringWorks() { DocumentId docId = new DocumentId("id:this:is::a:test"); DocumentRemove r = new DocumentRemove(docId); - assertTrue(r.toString().contains(docId.toString())); + assertThat(r.toString().contains(docId.toString()), is(true)); } @Test @@ -27,18 +27,18 @@ public class DocumentRemoveTestCase { DocumentRemove r2 = new DocumentRemove(new DocumentId("id:this:is::a:test")); DocumentRemove r3 = new DocumentRemove(new DocumentId("id:this:is::nonequal")); - assertEquals(r1, r1); - assertEquals(r1, r2); - assertEquals(r2, r1); - assertEquals(r1.hashCode(), r2.hashCode()); + assertThat(r1, equalTo(r1)); + assertThat(r1, equalTo(r2)); + assertThat(r2, equalTo(r1)); + assertThat(r1.hashCode(), equalTo(r2.hashCode())); - assertNotEquals(r1, r3); - assertNotEquals(r3, r1); - assertNotEquals(r2, r3); - assertNotEquals(r3, r2); - assertNotEquals(r1.hashCode(), r3.hashCode()); + assertThat(r1, not(equalTo(r3))); + assertThat(r3, not(equalTo(r1))); + assertThat(r2, not(equalTo(r3))); + assertThat(r3, not(equalTo(r2))); + assertThat(r1.hashCode(), not(equalTo(r3.hashCode()))); - assertNotEquals(r1, new Object()); - assertFalse(r1.equals("banana")); + assertThat(r1, not(equalTo(new Object()))); + assertThat(r1.equals("banana"), is(false)); } } diff --git a/document/src/test/java/com/yahoo/document/DocumentTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTestCase.java index df1a56cf8e1..be6544563ed 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTestCase.java @@ -18,8 +18,10 @@ import com.yahoo.document.datatypes.Raw; import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.datatypes.Struct; import com.yahoo.document.datatypes.WeightedSet; +import com.yahoo.document.serialization.DocumentDeserializer; import com.yahoo.document.serialization.DocumentDeserializerFactory; import com.yahoo.document.serialization.DocumentReader; +import com.yahoo.document.serialization.DocumentSerializer; import com.yahoo.document.serialization.DocumentSerializerFactory; import com.yahoo.document.serialization.XmlDocumentWriter; import com.yahoo.io.GrowableByteBuffer; @@ -31,13 +33,15 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; -import java.util.Arrays; import java.util.Map; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -1079,14 +1083,15 @@ public class DocumentTestCase extends DocumentTestCaseBase { Map<String, Object> parsed = new ObjectMapper().readValue(json, new TypeReference<Map<String, Object>>() { }); assertEquals(parsed.get("id"), "id:ns:sertest::foobar"); - assertTrue(parsed.get("fields") instanceof Map); + assertThat(parsed.get("fields"), instanceOf(Map.class)); Object fieldMap = parsed.get("fields"); if (fieldMap instanceof Map) { Map<?, ?> fields = (Map<?, ?>) fieldMap; assertEquals(fields.get("mailid"), "emailfromalicetobob"); assertEquals(fields.get("date"), -2013512400); - assertTrue(fields.get("docindoc") instanceof Map); - assertTrue(fields.keySet().containsAll(Arrays.asList("mailid", "date", "attachmentcount", "rawfield", "weightedfield", "docindoc", "mapfield", "myboolfield"))); + assertThat(fields.get("docindoc"), instanceOf(Map.class)); + assertThat(fields.keySet(), + containsInAnyOrder("mailid", "date", "attachmentcount", "rawfield", "weightedfield", "docindoc", "mapfield", "myboolfield")); } } diff --git a/document/src/test/java/com/yahoo/document/DocumentTypeIdTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTypeIdTestCase.java index c425ebea2c2..16f757d4379 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTypeIdTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTypeIdTestCase.java @@ -3,10 +3,10 @@ package com.yahoo.document; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -17,7 +17,7 @@ public class DocumentTypeIdTestCase { @Test public void requireThatToStringWorks() { DocumentTypeId r = new DocumentTypeId(123); - assertTrue(r.toString().contains("123")); + assertThat(r.toString().contains("123"), is(true)); } @Test @@ -26,24 +26,24 @@ public class DocumentTypeIdTestCase { DocumentTypeId r2 = new DocumentTypeId(123); DocumentTypeId r3 = new DocumentTypeId(456); - assertEquals(r1, r1); - assertEquals(r1, r2); - assertEquals(r2, r1); - assertEquals(r1.hashCode(), r2.hashCode()); + assertThat(r1, equalTo(r1)); + assertThat(r1, equalTo(r2)); + assertThat(r2, equalTo(r1)); + assertThat(r1.hashCode(), equalTo(r2.hashCode())); - assertNotEquals(r1, r3); - assertNotEquals(r3, r1); - assertNotEquals(r2, r3); - assertNotEquals(r3, r2); - assertNotEquals(r1.hashCode(), r3.hashCode()); + assertThat(r1, not(equalTo(r3))); + assertThat(r3, not(equalTo(r1))); + assertThat(r2, not(equalTo(r3))); + assertThat(r3, not(equalTo(r2))); + assertThat(r1.hashCode(), not(equalTo(r3.hashCode()))); - assertNotEquals(r1, new Object()); - assertFalse(r1.equals("foobar")); + assertThat(r1, not(equalTo(new Object()))); + assertThat(r1.equals("foobar"), is(false)); } @Test public void requireThatAccessorsWork() { DocumentTypeId r1 = new DocumentTypeId(123); - assertEquals(123, r1.getId()); + assertThat(r1.getId(), equalTo(123)); } } diff --git a/document/src/test/java/com/yahoo/document/FieldPathEntryTestCase.java b/document/src/test/java/com/yahoo/document/FieldPathEntryTestCase.java index 791310ee6f2..059d65f88f8 100644 --- a/document/src/test/java/com/yahoo/document/FieldPathEntryTestCase.java +++ b/document/src/test/java/com/yahoo/document/FieldPathEntryTestCase.java @@ -3,8 +3,9 @@ package com.yahoo.document; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -19,19 +20,19 @@ public class FieldPathEntryTestCase { FieldPathEntry.KeyParseResult result4 = new FieldPathEntry.KeyParseResult("banana", 3); - assertEquals(result1, result2); - assertEquals(result2, result1); - assertEquals(result1.hashCode(), result2.hashCode()); - assertEquals(result1.toString(), result2.toString()); + assertThat(result1, equalTo(result2)); + assertThat(result2, equalTo(result1)); + assertThat(result1.hashCode(), equalTo(result2.hashCode())); + assertThat(result1.toString(), equalTo(result2.toString())); - assertNotEquals(result1, result3); - assertNotEquals(result3, result1); - assertNotEquals(result1.hashCode(), result3.hashCode()); - assertNotEquals(result1.toString(), result3.toString()); + assertThat(result1, not(equalTo(result3))); + assertThat(result3, not(equalTo(result1))); + assertThat(result1.hashCode(), not(equalTo(result3.hashCode()))); + assertThat(result1.toString(), not(equalTo(result3.toString()))); - assertNotEquals(result1, result4); - assertNotEquals(result4, result1); - assertNotEquals(result1.hashCode(), result4.hashCode()); - assertNotEquals(result1.toString(), result4.toString()); + assertThat(result1, not(equalTo(result4))); + assertThat(result4, not(equalTo(result1))); + assertThat(result1.hashCode(), not(equalTo(result4.hashCode()))); + assertThat(result1.toString(), not(equalTo(result4.toString()))); } } diff --git a/document/src/test/java/com/yahoo/document/NumericDataTypeTestCase.java b/document/src/test/java/com/yahoo/document/NumericDataTypeTestCase.java index 28f6f682755..05f68570e60 100644 --- a/document/src/test/java/com/yahoo/document/NumericDataTypeTestCase.java +++ b/document/src/test/java/com/yahoo/document/NumericDataTypeTestCase.java @@ -5,9 +5,8 @@ import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.IntegerFieldValue; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.fail; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -19,8 +18,8 @@ public class NumericDataTypeTestCase { public void basic() { NumericDataType type = new NumericDataType("foo", 0, FieldValue.class, IntegerFieldValue.getFactory()); NumericDataType clonedType = type.clone(); - assertEquals(type,clonedType); - assertNotSame(type, clonedType); + assertThat(type, equalTo(clonedType)); + assertThat(type, not(sameInstance(clonedType))); } @Test diff --git a/document/src/test/java/com/yahoo/document/TemporaryDataTypeTestCase.java b/document/src/test/java/com/yahoo/document/TemporaryDataTypeTestCase.java index 663ea96f40f..4a4895b7e78 100644 --- a/document/src/test/java/com/yahoo/document/TemporaryDataTypeTestCase.java +++ b/document/src/test/java/com/yahoo/document/TemporaryDataTypeTestCase.java @@ -4,8 +4,9 @@ package com.yahoo.document; import com.yahoo.document.datatypes.StringFieldValue; import org.junit.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; /** * @author Einar M R Rosenvinge @@ -15,10 +16,10 @@ public class TemporaryDataTypeTestCase { @Test public void requireNulls() { TemporaryDataType type = new TemporaryDataType(0, ""); - assertNull(type.createFieldValue(new Object())); - assertNull(type.createFieldValue()); - assertNull(type.getValueClass()); - assertFalse(type.isValueCompatible(new StringFieldValue(""))); + assertThat(type.createFieldValue(new Object()), nullValue()); + assertThat(type.createFieldValue(), nullValue()); + assertThat(type.getValueClass(), nullValue()); + assertThat(type.isValueCompatible(new StringFieldValue("")), is(false)); } } diff --git a/document/src/test/java/com/yahoo/document/TemporaryStructuredDataTypeTestCase.java b/document/src/test/java/com/yahoo/document/TemporaryStructuredDataTypeTestCase.java index 431d4d9746c..d785faa146a 100644 --- a/document/src/test/java/com/yahoo/document/TemporaryStructuredDataTypeTestCase.java +++ b/document/src/test/java/com/yahoo/document/TemporaryStructuredDataTypeTestCase.java @@ -3,8 +3,9 @@ package com.yahoo.document; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -14,10 +15,10 @@ public class TemporaryStructuredDataTypeTestCase { @Test public void basic() { TemporaryStructuredDataType type = TemporaryStructuredDataType.create("banana"); - assertEquals("banana", type.getName()); + assertThat(type.getName(), equalTo("banana")); int originalId = type.getId(); type.setName("apple"); - assertEquals("apple", type.getName()); - assertNotEquals(originalId, type.getId()); + assertThat(type.getName(), equalTo("apple")); + assertThat(originalId, not(equalTo(type.getId()))); } } diff --git a/document/src/test/java/com/yahoo/document/annotation/Bug4475379TestCase.java b/document/src/test/java/com/yahoo/document/annotation/Bug4475379TestCase.java index 3d2a1fd2d90..6ca076ad3c6 100755 --- a/document/src/test/java/com/yahoo/document/annotation/Bug4475379TestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/Bug4475379TestCase.java @@ -13,7 +13,8 @@ import org.junit.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -31,7 +32,7 @@ public class Bug4475379TestCase { annotate(manager, doc); Document anotherDoc = doc.clone(); - assertEquals(doc, anotherDoc); + assertThat(doc, equalTo(anotherDoc)); } public void annotate(DocumentTypeManager manager, Document document) { diff --git a/document/src/test/java/com/yahoo/document/annotation/DummySpanNodeTestCase.java b/document/src/test/java/com/yahoo/document/annotation/DummySpanNodeTestCase.java index 3566117b33d..d2c35f45ad8 100644 --- a/document/src/test/java/com/yahoo/document/annotation/DummySpanNodeTestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/DummySpanNodeTestCase.java @@ -3,10 +3,9 @@ package com.yahoo.document.annotation; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -17,14 +16,14 @@ public class DummySpanNodeTestCase { @Test public void basic() { DummySpanNode node = DummySpanNode.INSTANCE; - assertEquals(0, node.getFrom()); - assertEquals(0, node.getTo()); - assertEquals(0, node.getLength()); - assertNull(node.getText("baba")); - assertTrue(node.isLeafNode()); - assertFalse(node.childIterator().hasNext()); - assertFalse(node.childIterator().hasPrevious()); - assertFalse(node.childIteratorRecursive().hasNext()); - assertFalse(node.childIteratorRecursive().hasPrevious()); + assertThat(node.getFrom(), is(0)); + assertThat(node.getTo(), is(0)); + assertThat(node.getLength(), is(0)); + assertThat(node.getText("baba"), nullValue()); + assertThat(node.isLeafNode(), is(true)); + assertThat(node.childIterator().hasNext(), is(false)); + assertThat(node.childIterator().hasPrevious(), is(false)); + assertThat(node.childIteratorRecursive().hasNext(), is(false)); + assertThat(node.childIteratorRecursive().hasPrevious(), is(false)); } } diff --git a/document/src/test/java/com/yahoo/document/annotation/IndexKeySpanTreeTestCase.java b/document/src/test/java/com/yahoo/document/annotation/IndexKeySpanTreeTestCase.java index 8c5a481764d..3b403680577 100644 --- a/document/src/test/java/com/yahoo/document/annotation/IndexKeySpanTreeTestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/IndexKeySpanTreeTestCase.java @@ -3,8 +3,8 @@ package com.yahoo.document.annotation; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -14,27 +14,27 @@ public class IndexKeySpanTreeTestCase { @Test public void testIndexKeys() throws Exception { SpanTree tree = new SpanTree("something"); - assertTrue(tree.getCurrentIndexes().isEmpty()); + assertThat(tree.getCurrentIndexes().isEmpty(), is(true)); tree.createIndex(SpanTree.IndexKey.SPAN_NODE); - assertEquals(1, tree.getCurrentIndexes().size()); - assertEquals(SpanTree.IndexKey.SPAN_NODE, tree.getCurrentIndexes().iterator().next()); + assertThat(tree.getCurrentIndexes().size(), is(1)); + assertThat(tree.getCurrentIndexes().iterator().next(), is(SpanTree.IndexKey.SPAN_NODE)); tree.clearIndexes(); - assertTrue(tree.getCurrentIndexes().isEmpty()); + assertThat(tree.getCurrentIndexes().isEmpty(), is(true)); tree.createIndex(SpanTree.IndexKey.ANNOTATION_TYPE); - assertEquals(1, tree.getCurrentIndexes().size()); - assertEquals(SpanTree.IndexKey.ANNOTATION_TYPE, tree.getCurrentIndexes().iterator().next()); + assertThat(tree.getCurrentIndexes().size(), is(1)); + assertThat(tree.getCurrentIndexes().iterator().next(), is(SpanTree.IndexKey.ANNOTATION_TYPE)); tree.clearIndexes(); - assertTrue(tree.getCurrentIndexes().isEmpty()); + assertThat(tree.getCurrentIndexes().isEmpty(), is(true)); } @Test(expected = IllegalArgumentException.class) public void testSwitchIndexes() { SpanTree tree = new SpanTree("something"); - assertTrue(tree.getCurrentIndexes().isEmpty()); + assertThat(tree.getCurrentIndexes().isEmpty(), is(true)); tree.createIndex(SpanTree.IndexKey.SPAN_NODE); tree.createIndex(SpanTree.IndexKey.ANNOTATION_TYPE); } @@ -42,7 +42,7 @@ public class IndexKeySpanTreeTestCase { @Test(expected = IllegalArgumentException.class) public void testSwitchIndexes2() { SpanTree tree = new SpanTree("something"); - assertTrue(tree.getCurrentIndexes().isEmpty()); + assertThat(tree.getCurrentIndexes().isEmpty(), is(true)); tree.createIndex(SpanTree.IndexKey.ANNOTATION_TYPE); tree.createIndex(SpanTree.IndexKey.SPAN_NODE); } @@ -50,7 +50,7 @@ public class IndexKeySpanTreeTestCase { @Test public void testSwitchIndexes3() { SpanTree tree = new SpanTree("something"); - assertTrue(tree.getCurrentIndexes().isEmpty()); + assertThat(tree.getCurrentIndexes().isEmpty(), is(true)); tree.createIndex(SpanTree.IndexKey.ANNOTATION_TYPE); tree.clearIndex(SpanTree.IndexKey.SPAN_NODE); } diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java index 522176d7504..c191851acbe 100644 --- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java +++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java @@ -79,10 +79,13 @@ import static com.yahoo.document.json.readers.SingleValueReader.UPDATE_DIVIDE; import static com.yahoo.document.json.readers.SingleValueReader.UPDATE_INCREMENT; import static com.yahoo.document.json.readers.SingleValueReader.UPDATE_MULTIPLY; import static com.yahoo.test.json.JsonTestHelper.inputJson; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; 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.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -794,8 +797,8 @@ public class JsonReaderTestCase { d = r.next(); DocumentUpdate update = (DocumentUpdate) d; checkSimpleArrayAdd(update); - assertTrue(update.getCreateIfNonExistent()); - assertEquals("bla", update.getCondition().getSelection()); + assertThat(update.getCreateIfNonExistent(), is(true)); + assertThat(update.getCondition().getSelection(), is("bla")); d = r.next(); DocumentRemove remove = (DocumentRemove) d; @@ -830,8 +833,8 @@ public class JsonReaderTestCase { for (int x = 0; x < documentsCreated; x++) { DocumentUpdate update = (DocumentUpdate) r.next(); checkSimpleArrayAdd(update); - assertTrue(update.getCreateIfNonExistent()); - assertEquals("bla", update.getCondition().getSelection()); + assertThat(update.getCreateIfNonExistent(), is(true)); + assertThat(update.getCondition().getSelection(), is("bla")); } @@ -1777,7 +1780,7 @@ public class JsonReaderTestCase { @Test public void requireThatUnknownDocTypeThrowsIllegalArgumentException() { exception.expect(IllegalArgumentException.class); - exception.expectMessage("Document type walrus does not exist"); + exception.expectMessage(containsString("Document type walrus does not exist")); final String jsonData = inputJson( "[", @@ -1959,7 +1962,7 @@ public class JsonReaderTestCase { // NOTE: Do not call this method multiple times from a test method as it's using the ExpectedException rule private void assertParserErrorMatches(String expectedError, String... json) { exception.expect(JsonReaderException.class); - exception.expectMessage(expectedError); + exception.expectMessage(containsString(expectedError)); String jsonData = inputJson(json); new JsonReader(types, jsonToInputStream(jsonData), parserFactory).next(); } diff --git a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java index feeac3d9da0..d1f02ae45e2 100644 --- a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java +++ b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java @@ -1,28 +1,8 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.select; -import com.yahoo.document.ArrayDataType; -import com.yahoo.document.DataType; -import com.yahoo.document.Document; -import com.yahoo.document.DocumentGet; -import com.yahoo.document.DocumentId; -import com.yahoo.document.DocumentOperation; -import com.yahoo.document.DocumentPut; -import com.yahoo.document.DocumentRemove; -import com.yahoo.document.DocumentType; -import com.yahoo.document.DocumentTypeManager; -import com.yahoo.document.DocumentUpdate; -import com.yahoo.document.Field; -import com.yahoo.document.MapDataType; -import com.yahoo.document.StructDataType; -import com.yahoo.document.WeightedSetDataType; -import com.yahoo.document.datatypes.Array; -import com.yahoo.document.datatypes.FloatFieldValue; -import com.yahoo.document.datatypes.IntegerFieldValue; -import com.yahoo.document.datatypes.MapFieldValue; -import com.yahoo.document.datatypes.StringFieldValue; -import com.yahoo.document.datatypes.Struct; -import com.yahoo.document.datatypes.WeightedSet; +import com.yahoo.document.*; +import com.yahoo.document.datatypes.*; import com.yahoo.document.select.convert.SelectionExpressionConverter; import com.yahoo.document.select.parser.ParseException; import com.yahoo.document.select.parser.TokenMgrException; @@ -52,7 +32,7 @@ public class DocumentSelectorTestCase { @Rule public final ExpectedException exceptionRule = ExpectedException.none(); - private static final DocumentTypeManager manager = new DocumentTypeManager(); + private static DocumentTypeManager manager = new DocumentTypeManager(); @Before public void setUp() { diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/XMLNumericFieldErrorMsgTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/XMLNumericFieldErrorMsgTestCase.java index 3c93dc1429d..298960ff8ba 100644 --- a/document/src/test/java/com/yahoo/vespaxmlparser/XMLNumericFieldErrorMsgTestCase.java +++ b/document/src/test/java/com/yahoo/vespaxmlparser/XMLNumericFieldErrorMsgTestCase.java @@ -11,7 +11,8 @@ import org.junit.Test; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; /** @@ -43,7 +44,7 @@ public class XMLNumericFieldErrorMsgTestCase { new Document(documentReader); fail("Sorry mac"); } catch (DeserializationException e) { - assertTrue(e.getMessage().contains("Field 'floatfield': Invalid float \"\"")); + assertThat(e.getMessage(), e.getMessage().contains("Field 'floatfield': Invalid float \"\""), is(true)); } } @@ -58,7 +59,7 @@ public class XMLNumericFieldErrorMsgTestCase { new Document(documentReader); fail("Sorry mac"); } catch (DeserializationException e) { - assertTrue(e.getMessage().contains("Field 'doublefield': Invalid double \"\"")); + assertThat(e.getMessage(), e.getMessage().contains("Field 'doublefield': Invalid double \"\""), is(true)); } } @@ -73,7 +74,7 @@ public class XMLNumericFieldErrorMsgTestCase { new Document(documentReader); fail("Sorry mac"); } catch (DeserializationException e) { - assertTrue(e.getMessage().contains("Field 'longfield': Invalid long \"\"")); + assertThat(e.getMessage(), e.getMessage().contains("Field 'longfield': Invalid long \"\""), is(true)); } } @@ -88,7 +89,7 @@ public class XMLNumericFieldErrorMsgTestCase { new Document(documentReader); fail("Sorry mac"); } catch (DeserializationException e) { - assertTrue(e.getMessage().contains("Field 'intfield': Invalid integer \"\"")); + assertThat(e.getMessage(), e.getMessage().contains("Field 'intfield': Invalid integer \"\""), is(true)); } } @@ -103,7 +104,7 @@ public class XMLNumericFieldErrorMsgTestCase { new Document(documentReader); fail("Sorry mac"); } catch (DeserializationException e) { - assertTrue(e.getMessage().contains("Field 'bytefield': Invalid byte \"\"")); + assertThat(e.getMessage(), e.getMessage().contains("Field 'bytefield': Invalid byte \"\""), is(true)); } } 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())); } } diff --git a/messagebus/pom.xml b/messagebus/pom.xml index 9bd123ad6bd..358ce7cc63f 100644 --- a/messagebus/pom.xml +++ b/messagebus/pom.xml @@ -20,6 +20,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-all</artifactId> + <version>1.3</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>com.yahoo.vespa</groupId> <artifactId>vespajlib</artifactId> <version>${project.version}</version> diff --git a/messagebus/src/test/java/com/yahoo/messagebus/network/local/LocalNetworkTest.java b/messagebus/src/test/java/com/yahoo/messagebus/network/local/LocalNetworkTest.java index aec38e7d157..e2706a66671 100644 --- a/messagebus/src/test/java/com/yahoo/messagebus/network/local/LocalNetworkTest.java +++ b/messagebus/src/test/java/com/yahoo/messagebus/network/local/LocalNetworkTest.java @@ -2,23 +2,7 @@ package com.yahoo.messagebus.network.local; import com.yahoo.concurrent.SystemTimer; -import com.yahoo.messagebus.DestinationSession; -import com.yahoo.messagebus.DestinationSessionParams; -import com.yahoo.messagebus.EmptyReply; -import com.yahoo.messagebus.ErrorCode; -import com.yahoo.messagebus.IntermediateSession; -import com.yahoo.messagebus.IntermediateSessionParams; -import com.yahoo.messagebus.Message; -import com.yahoo.messagebus.MessageBus; -import com.yahoo.messagebus.MessageBusParams; -import com.yahoo.messagebus.MessageHandler; -import com.yahoo.messagebus.Reply; -import com.yahoo.messagebus.ReplyHandler; -import com.yahoo.messagebus.Result; -import com.yahoo.messagebus.SourceSession; -import com.yahoo.messagebus.SourceSessionParams; -import com.yahoo.messagebus.StaticThrottlePolicy; -import com.yahoo.messagebus.ThrottlePolicy; +import com.yahoo.messagebus.*; import com.yahoo.messagebus.routing.Hop; import com.yahoo.messagebus.routing.Route; import com.yahoo.messagebus.test.SimpleMessage; @@ -30,8 +14,12 @@ import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.number.OrderingComparison.lessThan; +import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** @@ -55,28 +43,28 @@ public class LocalNetworkTest { Message msg = new SimpleMessage("foo"); msg.setRoute(new Route().addHop(Hop.parse(intermediate.getConnectionSpec())) .addHop(Hop.parse(destination.getConnectionSpec()))); - assertTrue(source.send(msg).isAccepted()); + assertThat(source.send(msg).isAccepted(), is(true)); msg = serverB.messages.poll(60, TimeUnit.SECONDS); - assertTrue(msg instanceof SimpleMessage); - assertEquals("foo", ((SimpleMessage)msg).getValue()); + assertThat(msg, instanceOf(SimpleMessage.class)); + assertThat(((SimpleMessage)msg).getValue(), is("foo")); intermediate.forward(msg); msg = serverC.messages.poll(60, TimeUnit.SECONDS); - assertTrue(msg instanceof SimpleMessage); - assertEquals("foo", ((SimpleMessage)msg).getValue()); + assertThat(msg, instanceOf(SimpleMessage.class)); + assertThat(((SimpleMessage)msg).getValue(), is("foo")); Reply reply = new SimpleReply("bar"); reply.swapState(msg); destination.reply(reply); reply = serverB.replies.poll(60, TimeUnit.SECONDS); - assertTrue(reply instanceof SimpleReply); - assertEquals("bar", ((SimpleReply)reply).getValue()); + assertThat(reply, instanceOf(SimpleReply.class)); + assertThat(((SimpleReply)reply).getValue(), is("bar")); intermediate.forward(reply); reply = serverA.replies.poll(60, TimeUnit.SECONDS); - assertTrue(reply instanceof SimpleReply); - assertEquals("bar", ((SimpleReply)reply).getValue()); + assertThat(reply, instanceOf(SimpleReply.class)); + assertThat(((SimpleReply)reply).getValue(), is("bar")); serverA.mbus.destroy(); serverB.mbus.destroy(); @@ -89,9 +77,9 @@ public class LocalNetworkTest { final SourceSession source = server.newSourceSession(); final Message msg = new SimpleMessage("foo").setRoute(Route.parse("bar")); - assertTrue(source.send(msg).isAccepted()); + assertThat(source.send(msg).isAccepted(), is(true)); final Reply reply = server.replies.poll(60, TimeUnit.SECONDS); - assertTrue(reply instanceof EmptyReply); + assertThat(reply, instanceOf(EmptyReply.class)); server.mbus.destroy(); } @@ -112,7 +100,7 @@ public class LocalNetworkTest { Message msg = new SimpleMessage("foo"); msg.setRoute(new Route().addHop(Hop.parse(intermediate.getConnectionSpec())) .addHop(Hop.parse(destination.getConnectionSpec()))); - assertTrue(source.sendBlocking(msg).isAccepted()); + assertThat(source.sendBlocking(msg).isAccepted(), is(true)); long start = SystemTimer.INSTANCE.milliTime(); Message msg2 = new SimpleMessage("foo2"); msg2.setRoute(new Route().addHop(Hop.parse(intermediate.getConnectionSpec())) @@ -120,28 +108,28 @@ public class LocalNetworkTest { long TIMEOUT = 1000; msg2.setTimeRemaining(TIMEOUT); Result res = source.sendBlocking(msg2); - assertFalse(res.isAccepted()); + assertThat(res.isAccepted(), is(false)); assertEquals(ErrorCode.TIMEOUT, res.getError().getCode()); assertTrue(res.getError().getMessage().endsWith("Timed out in sendQ")); long end = SystemTimer.INSTANCE.milliTime(); - assertTrue(end >= start+TIMEOUT); - assertTrue(end < start+5*TIMEOUT); + assertThat(end, greaterThanOrEqualTo(start+TIMEOUT)); + assertThat(end, lessThan(start+5*TIMEOUT)); msg = serverB.messages.poll(60, TimeUnit.SECONDS); - assertTrue(msg instanceof SimpleMessage); - assertEquals("foo", ((SimpleMessage)msg).getValue()); + assertThat(msg, instanceOf(SimpleMessage.class)); + assertThat(((SimpleMessage)msg).getValue(), is("foo")); intermediate.forward(msg); msg = serverC.messages.poll(60, TimeUnit.SECONDS); - assertTrue(msg instanceof SimpleMessage); - assertEquals("foo", ((SimpleMessage)msg).getValue()); + assertThat(msg, instanceOf(SimpleMessage.class)); + assertThat(((SimpleMessage)msg).getValue(), is("foo")); Reply reply = new SimpleReply("bar"); reply.swapState(msg); destination.reply(reply); reply = serverB.replies.poll(60, TimeUnit.SECONDS); - assertTrue(reply instanceof SimpleReply); - assertEquals("bar", ((SimpleReply)reply).getValue()); + assertThat(reply, instanceOf(SimpleReply.class)); + assertThat(((SimpleReply)reply).getValue(), is("bar")); intermediate.forward(reply); reply = serverA.replies.poll(60, TimeUnit.SECONDS); @@ -149,8 +137,8 @@ public class LocalNetworkTest { assertTrue(reply.getError(0).getMessage().endsWith("Timed out in sendQ")); reply = serverA.replies.poll(60, TimeUnit.SECONDS); - assertTrue(reply instanceof SimpleReply); - assertEquals("bar", ((SimpleReply)reply).getValue()); + assertThat(reply, instanceOf(SimpleReply.class)); + assertThat(((SimpleReply)reply).getValue(), is("bar")); serverA.mbus.destroy(); serverB.mbus.destroy(); diff --git a/yolean/src/test/java/com/yahoo/yolean/chain/ChainBuilderTest.java b/yolean/src/test/java/com/yahoo/yolean/chain/ChainBuilderTest.java index 70bb0ab1397..60629e05636 100644 --- a/yolean/src/test/java/com/yahoo/yolean/chain/ChainBuilderTest.java +++ b/yolean/src/test/java/com/yahoo/yolean/chain/ChainBuilderTest.java @@ -9,9 +9,9 @@ import java.util.List; import static com.yahoo.yolean.chain.Dependencies.after; import static com.yahoo.yolean.chain.Dependencies.before; import static com.yahoo.yolean.chain.Dependencies.provides; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsIterableContainingInOrder.contains; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** @@ -100,7 +100,7 @@ public class ChainBuilderTest { public void build_empty_chain() { Chain<Filter> chain = getChain().build(); assertTrue(chain.isEmpty()); - assertEquals("myChain", chain.id()); + assertThat(chain.id(), is("myChain")); } @Test @@ -140,7 +140,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b).add(a, before(b)).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -151,7 +151,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b, after(a)).add(a).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -162,7 +162,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b).add(a, before(b.getClass())).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -173,7 +173,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b, after(a.getClass())).add(a).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -184,7 +184,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b).add(a, before(FilterB.class)).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -195,7 +195,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b, after(FilterA.class)).add(a).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -206,7 +206,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b, provides("B")).add(a, before("B")).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -217,7 +217,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b, after("A")).add(a, provides("A")).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -228,7 +228,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(providesA).add(beforeA).build(); - assertEquals(new Chain<>("myChain", beforeA, providesA), chain); + assertThat(chain, is(new Chain<>("myChain", beforeA, providesA))); } @Test @@ -239,7 +239,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(afterA).add(providesA).build(); - assertEquals(new Chain<>("myChain", providesA, afterA), chain); + assertThat(chain, is(new Chain<>("myChain", providesA, afterA))); } @Test @@ -250,7 +250,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b).add(a, before("*")).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -261,7 +261,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b, after("*")).add(a).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -272,7 +272,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(a).add(beforeAll).build(); - assertEquals(new Chain<>("myChain", beforeAll, a), chain); + assertThat(chain, is(new Chain<>("myChain", beforeAll, a))); } @Test @@ -283,7 +283,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(afterAll).add(a).build(); - assertEquals(new Chain<>("myChain", a, afterAll), chain); + assertThat(chain, is(new Chain<>("myChain", a, afterAll))); } @Test @@ -294,7 +294,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(beforeAll).add(beforeBeforeAll).build(); - assertEquals(new Chain<>("myChain", beforeBeforeAll, beforeAll), chain); + assertThat(chain, is(new Chain<>("myChain", beforeBeforeAll, beforeAll))); } @Test @@ -305,7 +305,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(afterAfterAll).add(afterAll).build(); - assertEquals(new Chain<>("myChain", afterAll, afterAfterAll), chain); + assertThat(chain, is(new Chain<>("myChain", afterAll, afterAfterAll))); } @Test @@ -316,7 +316,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(beforeAll).add(first, before("BeforeAll")).build(); - assertEquals(new Chain<>("myChain", first, beforeAll), chain); + assertThat(chain, is(new Chain<>("myChain", first, beforeAll))); } @Test @@ -327,7 +327,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(last, after("AfterAll")).add(afterAll).build(); - assertEquals(new Chain<>("myChain", afterAll, last), chain); + assertThat(chain, is(new Chain<>("myChain", afterAll, last))); } @Test @@ -338,7 +338,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(b, after(a.getClass().getName())).add(a).build(); - assertEquals(new Chain<>("myChain", a, b), chain); + assertThat(chain, is(new Chain<>("myChain", a, b))); } @Test @@ -350,7 +350,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(last, after("A")).add(first, before("A")).add(extendsA).build(); - assertEquals(new Chain<>("myChain", first, extendsA, last), chain); + assertThat(chain, is(new Chain<>("myChain", first, extendsA, last))); } @Test @@ -362,7 +362,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(last, after("A")).add(first, before("ExtendsA")).add(extendsA).build(); - assertEquals(new Chain<>("myChain", first, extendsA, last), chain); + assertThat(chain, is(new Chain<>("myChain", first, extendsA, last))); } @Test @@ -373,7 +373,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(A, before("*")).add(beforeA_and_beforeB).add(B).build(); - assertEquals(new Chain<>("myChain", beforeA_and_beforeB, A, B), chain); + assertThat(chain, is(new Chain<>("myChain", beforeA_and_beforeB, A, B))); } @Test @@ -385,7 +385,7 @@ public class ChainBuilderTest { Chain<Filter> chain = getChain(). add(a).add(c).add(b, after(a), before(c)).build(); - assertEquals(new Chain<>("myChain", a, b, c), chain); + assertThat(chain, is(new Chain<>("myChain", a, b, c))); } private ChainBuilder<Filter> getChain() { diff --git a/yolean/src/test/java/com/yahoo/yolean/chain/ChainTest.java b/yolean/src/test/java/com/yahoo/yolean/chain/ChainTest.java index da9ae2c38e3..aa344d88f5a 100644 --- a/yolean/src/test/java/com/yahoo/yolean/chain/ChainTest.java +++ b/yolean/src/test/java/com/yahoo/yolean/chain/ChainTest.java @@ -3,8 +3,9 @@ package com.yahoo.yolean.chain; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; /** * @author Tony Vaagenes @@ -22,33 +23,33 @@ public class ChainTest { @Test public void empty_chain_toString() { Chain<Filter> c = new Chain<>("myChain"); - assertEquals("chain 'myChain'{}", c.toString()); + assertThat(c.toString(), is("chain 'myChain'{}")); } @Test public void singleton_chain_toString() { Chain<Filter> c = new Chain<>("myChain", new Filter()); - assertEquals("chain 'myChain'{ Filter }", c.toString()); + assertThat(c.toString(), is("chain 'myChain'{ Filter }")); } @Test public void chain_toString() { Chain<Filter> c = new Chain<>("myChain", new Filter(), new Filter(), new OtherFilter()); - assertEquals("chain 'myChain'{ Filter -> Filter -> OtherFilter }", c.toString()); + assertThat(c.toString(), is("chain 'myChain'{ Filter -> Filter -> OtherFilter }")); } @Test public void non_equal_due_to_different_components() { - assertNotEquals(new Chain<>("a", new Filter()), new Chain<>("a", new Filter())); + assertThat(new Chain<>("a", new Filter()), is(not(new Chain<>("a", new Filter())))); } @Test public void non_equal_due_to_different_size_comopnents() { - assertNotEquals(new Chain<>("a", new Filter()), new Chain<Filter>("a")); + assertThat(new Chain<>("a", new Filter()), is(not(new Chain<Filter>("a")))); } @Test public void hashCode_equals() { - assertEquals(new Chain<>("a").hashCode(), new Chain<Filter>("a").hashCode()); + assertThat(new Chain<>("a").hashCode(), is(new Chain<Filter>("a").hashCode())); } } diff --git a/yolean/src/test/java/com/yahoo/yolean/chain/DirectedGraphTest.java b/yolean/src/test/java/com/yahoo/yolean/chain/DirectedGraphTest.java index b37c57b536b..0ff600430b6 100644 --- a/yolean/src/test/java/com/yahoo/yolean/chain/DirectedGraphTest.java +++ b/yolean/src/test/java/com/yahoo/yolean/chain/DirectedGraphTest.java @@ -4,14 +4,13 @@ package com.yahoo.yolean.chain; import org.junit.Before; import org.junit.Test; -import java.util.Arrays; - -import static org.junit.Assert.assertTrue; +import static org.hamcrest.collection.IsIterableContainingInOrder.contains; +import static org.junit.Assert.assertThat; public class DirectedGraphTest { private DirectedGraph graph; - private final Vertex[] v = new Vertex[10]; + private Vertex[] v = new Vertex[10]; @Before public void setup() { @@ -27,7 +26,7 @@ public class DirectedGraphTest { graph.addVertex(v[0]); graph.addBeginningVertex(v[1]); - assertTrue(graph.topologicalSort().containsAll(Arrays.asList(v[1], v[0]))); + assertThat(graph.topologicalSort(), contains(v[1], v[0])); } @Test @@ -36,7 +35,7 @@ public class DirectedGraphTest { graph.addBeginningVertex(v[1]); graph.addEdge(v[0], v[1]); - assertTrue(graph.topologicalSort().containsAll(Arrays.asList(v[0], v[1]))); + assertThat(graph.topologicalSort(), contains(v[0], v[1])); } static class TestVertex implements Vertex { diff --git a/yolean/src/test/java/com/yahoo/yolean/chain/EnumeratedIdentitySetTest.java b/yolean/src/test/java/com/yahoo/yolean/chain/EnumeratedIdentitySetTest.java index 5f0692e186f..aded98914c5 100644 --- a/yolean/src/test/java/com/yahoo/yolean/chain/EnumeratedIdentitySetTest.java +++ b/yolean/src/test/java/com/yahoo/yolean/chain/EnumeratedIdentitySetTest.java @@ -16,7 +16,6 @@ import static java.util.Collections.singleton; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -38,13 +37,13 @@ public class EnumeratedIdentitySetTest { @Test public void size() { EnumeratedIdentitySet<Element> set = new EnumeratedIdentitySet<>(elements); - assertEquals(elements.size(), set.size()); + assertThat(set.size(), is(elements.size())); set.add(elements.get(0)); - assertEquals(elements.size(), set.size()); + assertThat(set.size(), is(elements.size())); set.remove(elements.get(0)); - assertEquals(elements.size() - 1, set.size()); + assertThat(set.size(), is(elements.size() - 1)); } @Test @@ -74,8 +73,8 @@ public class EnumeratedIdentitySetTest { count++; } - assertEquals(count, collectedElements.size()); - assertEquals(elements.size(), collectedElements.size()); + assertThat(collectedElements.size(), is(count)); + assertThat(collectedElements.size(), is(elements.size())); for (Element element : elements) { assertTrue(collectedElements.containsKey(element)); @@ -151,7 +150,7 @@ public class EnumeratedIdentitySetTest { public void clear() { EnumeratedIdentitySet<Element> set = new EnumeratedIdentitySet<>(elements); set.clear(); - assertTrue(set.isEmpty()); + assertThat(set, empty()); } @Test @@ -196,7 +195,7 @@ public class EnumeratedIdentitySetTest { } List<Element> forceRenumber = set.insertionOrderedList(); - assertEquals(elements.size(), forceRenumber.size()); + assertThat(forceRenumber.size(), is(elements.size())); for (int i = 0; i < elements.size(); i++) { assertSame(forceRenumber.get(i), elements.get(i)); @@ -215,7 +214,7 @@ public class EnumeratedIdentitySetTest { } set.insertionOrderedList(); - assertTrue(set.numbers().isEmpty()); + assertThat(set.numbers(), empty()); set.add(new Element()); assertThat(set.numbers(), containsSameElements(singleton(0))); |