summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-12-21 15:18:14 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2021-12-21 15:43:26 +0100
commite0fb5474ac171436e263a4950d72a2a405d379a2 (patch)
tree0b754bd09a06ef419a56f9df586446b386106669 /application
parent28ae61202ad963955cf92719bab9b9d97181d5dd (diff)
GC use of deprecated junit assertThat and unify
Diffstat (limited to 'application')
-rw-r--r--application/pom.xml5
-rw-r--r--application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java4
-rw-r--r--application/src/test/java/com/yahoo/application/container/ContainerDocprocTest.java26
-rw-r--r--application/src/test/java/com/yahoo/application/container/ContainerProcessingTest.java16
-rw-r--r--application/src/test/java/com/yahoo/application/container/ContainerRequestTest.java9
-rw-r--r--application/src/test/java/com/yahoo/application/container/ContainerSchemaTest.java9
-rw-r--r--application/src/test/java/com/yahoo/application/container/ContainerTest.java30
-rw-r--r--application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java30
8 files changed, 52 insertions, 77 deletions
diff --git a/application/pom.xml b/application/pom.xml
index af25bda0f07..2496b8becc5 100644
--- a/application/pom.xml
+++ b/application/pom.xml
@@ -74,11 +74,6 @@
</exclusions>
</dependency>
<dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest-all</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java b/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java
index 215b0961509..800c30ac8b8 100644
--- a/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java
+++ b/application/src/test/java/com/yahoo/application/ApplicationBuilderTest.java
@@ -8,7 +8,6 @@ import org.junit.rules.ExpectedException;
import java.nio.file.Files;
-import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertTrue;
/**
@@ -49,6 +48,7 @@ public class ApplicationBuilderTest {
});
}
+ @SuppressWarnings("deprecation")
@Rule
public ExpectedException expectedException = ExpectedException.none();
@@ -56,7 +56,7 @@ public class ApplicationBuilderTest {
@SuppressWarnings("try") // application unreferenced inside try
public void builder_cannot_be_reused() throws Exception {
expectedException.expect(RuntimeException.class);
- expectedException.expectMessage(containsString("build method"));
+ expectedException.expectMessage("build method");
ApplicationBuilder builder = new ApplicationBuilder();
builder.servicesXml("<container version=\"1.0\" />");
diff --git a/application/src/test/java/com/yahoo/application/container/ContainerDocprocTest.java b/application/src/test/java/com/yahoo/application/container/ContainerDocprocTest.java
index 855a56293d0..7c786d35fab 100644
--- a/application/src/test/java/com/yahoo/application/container/ContainerDocprocTest.java
+++ b/application/src/test/java/com/yahoo/application/container/ContainerDocprocTest.java
@@ -16,10 +16,8 @@ import com.yahoo.processing.execution.chain.ChainRegistry;
import org.junit.Before;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.sameInstance;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
@@ -75,13 +73,13 @@ public class ContainerDocprocTest {
processing = com.yahoo.docproc.Processing.of(put);
progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
- assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
- assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
+ assertSame(progress, DocumentProcessor.Progress.DONE);
+ assertEquals("Terng Nyohz!", doc.getFieldValue("title").toString());
processing = com.yahoo.docproc.Processing.of(put);
progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
- assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
- assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
+ assertSame(progress, DocumentProcessor.Progress.DONE);
+ assertEquals("Great Album!", doc.getFieldValue("title").toString());
}
}
@@ -107,16 +105,16 @@ public class ContainerDocprocTest {
processing = com.yahoo.docproc.Processing.of(put);
progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
- assertThat(progress, instanceOf(DocumentProcessor.LaterProgress.class));
- assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
+ assertTrue(progress instanceof DocumentProcessor.LaterProgress);
+ assertEquals("Great Album!", doc.getFieldValue("title").toString());
progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
- assertThat(progress, instanceOf(DocumentProcessor.LaterProgress.class));
- assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
+ assertTrue(progress instanceof DocumentProcessor.LaterProgress);
+ assertEquals("Great Album!", doc.getFieldValue("title").toString());
progress = docProc.processOnce(ComponentSpecification.fromString(CHAIN_NAME), processing);
- assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
- assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
+ assertSame(progress, DocumentProcessor.Progress.DONE);
+ assertEquals("Terng Nyohz!", doc.getFieldValue("title").toString());
}
}
diff --git a/application/src/test/java/com/yahoo/application/container/ContainerProcessingTest.java b/application/src/test/java/com/yahoo/application/container/ContainerProcessingTest.java
index e0385543022..e5019d6b54f 100644
--- a/application/src/test/java/com/yahoo/application/container/ContainerProcessingTest.java
+++ b/application/src/test/java/com/yahoo/application/container/ContainerProcessingTest.java
@@ -10,10 +10,10 @@ import com.yahoo.processing.Response;
import org.junit.Before;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.containsString;
-import static org.junit.Assert.assertThat;
+import java.nio.charset.StandardCharsets;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author Einar M R Rosenvinge
@@ -50,7 +50,7 @@ public class ContainerProcessingTest {
req.properties().set("title", "Good day!");
Response response = processing.process(ComponentSpecification.fromString("foo"), req);
- assertThat(response.data().get(0).toString(), equalTo("Tbbq qnl!"));
+ assertEquals("Tbbq qnl!", response.data().get(0).toString());
}
}
@@ -69,7 +69,7 @@ public class ContainerProcessingTest {
container.handleRequest(
new com.yahoo.application.container.handler.Request("http://foo/processing/?chain=foo&title=" + foo.toString()));
- assertThat(response.getBody().length, is(SIZE+26));
+ assertEquals(SIZE+26, response.getBody().length);
}
}
}
@@ -84,9 +84,9 @@ public class ContainerProcessingTest {
byte[] rendered = processing.processAndRender(ComponentSpecification.fromString("foo"),
ComponentSpecification.fromString("default"), req);
- String renderedAsString = new String(rendered, "utf-8");
+ String renderedAsString = new String(rendered, StandardCharsets.UTF_8);
- assertThat(renderedAsString, containsString("Tbbq qnl!"));
+ assertTrue(renderedAsString.contains("Tbbq qnl!"));
}
}
diff --git a/application/src/test/java/com/yahoo/application/container/ContainerRequestTest.java b/application/src/test/java/com/yahoo/application/container/ContainerRequestTest.java
index 98f35d5ed6c..911d57a7d6e 100644
--- a/application/src/test/java/com/yahoo/application/container/ContainerRequestTest.java
+++ b/application/src/test/java/com/yahoo/application/container/ContainerRequestTest.java
@@ -15,9 +15,8 @@ import org.junit.Test;
import java.nio.charset.CharacterCodingException;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author Einar M R Rosenvinge
@@ -44,7 +43,7 @@ public class ContainerRequestTest {
try (JDisc container = JDisc.fromServicesXml(getXML(EchoRequestHandler.class.getCanonicalName(), "http://*/echo"), Networking.disable)) {
Response response = container.handleRequest(req);
- assertThat(response.getBodyAsString(), equalTo(DATA));
+ assertEquals(DATA, response.getBodyAsString());
req.toString();
response.toString();
}
@@ -57,7 +56,7 @@ public class ContainerRequestTest {
try (JDisc container = JDisc.fromServicesXml(getXML(HeaderEchoRequestHandler.class.getCanonicalName(), "http://*/echo"), Networking.disable)) {
Response response = container.handleRequest(req);
- assertThat(response.getHeaders().contains("X-Foo", "Bar"), is(true));
+ assertTrue(response.getHeaders().contains("X-Foo", "Bar"));
req.toString();
response.toString();
}
diff --git a/application/src/test/java/com/yahoo/application/container/ContainerSchemaTest.java b/application/src/test/java/com/yahoo/application/container/ContainerSchemaTest.java
index 40bdf023c63..e1e520bccc9 100644
--- a/application/src/test/java/com/yahoo/application/container/ContainerSchemaTest.java
+++ b/application/src/test/java/com/yahoo/application/container/ContainerSchemaTest.java
@@ -10,9 +10,8 @@ import org.junit.Test;
import java.nio.charset.StandardCharsets;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* @author gjoranv
@@ -28,7 +27,7 @@ public class ContainerSchemaTest {
byte[] rendered = container.search().processAndRender(ComponentSpecification.fromString("mychain"),
ComponentSpecification.fromString("XmlRenderer"), new Query(""));
String renderedAsString = new String(rendered, StandardCharsets.UTF_8);
- assertThat(renderedAsString, containsString(searcherId));
+ assertTrue(renderedAsString.contains(searcherId));
}
}
@@ -40,7 +39,7 @@ public class ContainerSchemaTest {
Search searching = container.search();
Result result = searching.process(ComponentSpecification.fromString("mychain"), new Query(""));
String hitTitle = result.hits().get(0).getField("title").toString();
- assertThat(hitTitle, is(searcherId));
+ assertEquals(searcherId, hitTitle);
}
}
diff --git a/application/src/test/java/com/yahoo/application/container/ContainerTest.java b/application/src/test/java/com/yahoo/application/container/ContainerTest.java
index a46ae6e1ef5..f36237066b5 100644
--- a/application/src/test/java/com/yahoo/application/container/ContainerTest.java
+++ b/application/src/test/java/com/yahoo/application/container/ContainerTest.java
@@ -8,9 +8,6 @@ import com.yahoo.application.container.handler.Request;
import com.yahoo.application.container.handler.Response;
import com.yahoo.application.container.handlers.TestHandler;
import com.yahoo.component.ComponentSpecification;
-import com.yahoo.container.Container;
-import com.yahoo.jdisc.http.server.jetty.JettyHttpServer;
-import com.yahoo.jdisc.service.ServerProvider;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import org.junit.Ignore;
@@ -20,11 +17,9 @@ import java.nio.charset.CharacterCodingException;
import java.nio.file.FileSystems;
import static com.yahoo.application.container.JDisc.fromServicesXml;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
@@ -73,7 +68,7 @@ public class ContainerTest {
"</services>", Networking.disable)) {
fail("expected exception");
} catch (Exception e) {
- assertThat(e.getMessage(), containsString("container id='id1', container id='', jdisc id=''"));
+ assertTrue(e.getMessage().contains("container id='id1', container id='', jdisc id=''"));
}
}
@@ -87,7 +82,7 @@ public class ContainerTest {
"</container>", Networking.disable)) {
Response response = container.handleRequest(new Request("http://foo/TestHandler"));
try {
- assertThat(response.getBodyAsString(), is(TestHandler.RESPONSE));
+ assertEquals(TestHandler.RESPONSE, response.getBodyAsString());
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
@@ -100,7 +95,7 @@ public class ContainerTest {
Networking.disable)) {
Result result = container.search().process(ComponentSpecification.fromString("default"),
new Query("?query=ignored"));
- assertThat(result.hits().get(0).getField("title").toString(), is("Heal the World!"));
+ assertEquals("Heal the World!", result.hits().get(0).getField("title").toString());
}
}
@@ -110,7 +105,7 @@ public class ContainerTest {
.servicesXml(CONTAINER_WITH_DOCUMENT_PROCESSING).build()) {
JDisc container = application.getJDisc("container");
DocumentProcessing processing = container.documentProcessing();
- assertThat(processing.getDocumentTypes().keySet(), hasItem("example"));
+ assertTrue(processing.getDocumentTypes().containsKey("example"));
}
}
@@ -123,7 +118,7 @@ public class ContainerTest {
servicesXml(CONTAINER_WITH_DOCUMENT_PROCESSING).build()) {
JDisc container = application.getJDisc("container");
DocumentProcessing processing = container.documentProcessing();
- assertThat(processing.getAnnotationTypes().keySet(), hasItem("exampleAnnotation"));
+ assertTrue(processing.getAnnotationTypes().containsKey("exampleAnnotation"));
}
}
@@ -138,7 +133,7 @@ public class ContainerTest {
private void sendRequest(JDisc jdisc) throws CharacterCodingException {
Response response = jdisc.handleRequest(new Request("http://foo/TestHandler"));
- assertThat(response.getBodyAsString(), is(TestHandler.RESPONSE));
+ assertEquals(TestHandler.RESPONSE, response.getBodyAsString());
}
public static final String CONTAINER_WITH_DOCUMENT_PROCESSING = //
@@ -169,13 +164,4 @@ public class ContainerTest {
return JDisc.fromServicesXml(xml, Networking.disable);
}
- public static int getListenPort() {
- for (ServerProvider server : Container.get().getServerProviderRegistry().allComponents()) {
- if (null != server && server instanceof JettyHttpServer) {
- return ((JettyHttpServer) server).getListenPort();
- }
- }
- throw new RuntimeException("No http server found");
- }
-
}
diff --git a/application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java b/application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java
index 315ccb9d708..edd2acb630d 100644
--- a/application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java
+++ b/application/src/test/java/com/yahoo/application/container/handler/ResponseTestCase.java
@@ -3,10 +3,8 @@ package com.yahoo.application.container.handler;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
/**
* @author Einar M R Rosenvinge
@@ -15,16 +13,16 @@ public class ResponseTestCase {
@Test
public void requireThatCharsetParsingWorks() {
- assertThat(Response.charset("text/foobar").toString().toLowerCase(), equalTo("utf-8"));
- assertThat(Response.charset("adsf").toString().toLowerCase(), equalTo("utf-8"));
- assertThat(Response.charset("").toString().toLowerCase(), equalTo("utf-8"));
- assertThat(Response.charset(null).toString().toLowerCase(), equalTo("utf-8"));
+ assertEquals("utf-8", Response.charset("text/foobar").toString().toLowerCase());
+ assertEquals("utf-8", Response.charset("adsf").toString().toLowerCase());
+ assertEquals("utf-8", Response.charset("").toString().toLowerCase());
+ assertEquals("utf-8", Response.charset(null).toString().toLowerCase());
- assertThat(Response.charset("something; charset=US-ASCII").toString().toLowerCase(), equalTo("us-ascii"));
- assertThat(Response.charset("something; charset=iso-8859-1").toString().toLowerCase(), equalTo("iso-8859-1"));
+ assertEquals("us-ascii", Response.charset("something; charset=US-ASCII").toString().toLowerCase());
+ assertEquals("iso-8859-1", Response.charset("something; charset=iso-8859-1").toString().toLowerCase());
- assertThat(Response.charset("something; charset=").toString().toLowerCase(), equalTo("utf-8"));
- assertThat(Response.charset("something; charset=bananarama").toString().toLowerCase(), equalTo("utf-8"));
+ assertEquals("utf-8", Response.charset("something; charset=").toString().toLowerCase());
+ assertEquals("utf-8", Response.charset("something; charset=bananarama").toString().toLowerCase());
}
@Test
@@ -32,9 +30,9 @@ public class ResponseTestCase {
Response res1 = new Response();
Response res2 = new Response(new byte[0]);
- assertThat(res1.getBody(), notNullValue());
- assertThat(res1.getBody().length, is(0));
- assertThat(res2.getBody(), notNullValue());
- assertThat(res2.getBody().length, is(0));
+ assertNotNull(res1.getBody());
+ assertEquals(0, res1.getBody().length);
+ assertNotNull(res2.getBody());
+ assertEquals(0, res2.getBody().length);
}
}