aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config-model-api/src/test/java/com/yahoo/config/model/api/ServiceInfoTest.java20
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpGetConfigHandlerTest.java4
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpHandlerTest.java4
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java3
-rw-r--r--container-core/src/main/java/com/yahoo/processing/request/Properties.java3
-rw-r--r--container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.java4
-rw-r--r--docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerAllMessageTypesTestCase.java8
-rw-r--r--document/src/test/java/com/yahoo/document/DocumentTypeTestCase.java23
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionConverterTestCase.java3
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionSearcherTestCase.java16
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionVisitorTestCase.java10
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java28
-rw-r--r--indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/linguistics/LinguisticsAnnotatorTestCase.java27
-rw-r--r--vespajlib/src/test/java/com/yahoo/collections/LazyMapTest.java12
14 files changed, 80 insertions, 85 deletions
diff --git a/config-model-api/src/test/java/com/yahoo/config/model/api/ServiceInfoTest.java b/config-model-api/src/test/java/com/yahoo/config/model/api/ServiceInfoTest.java
index f1824763c12..b249b82d818 100644
--- a/config-model-api/src/test/java/com/yahoo/config/model/api/ServiceInfoTest.java
+++ b/config-model-api/src/test/java/com/yahoo/config/model/api/ServiceInfoTest.java
@@ -3,8 +3,8 @@ package com.yahoo.config.model.api;
import org.junit.Test;
-import java.util.Arrays;
-import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@@ -17,14 +17,14 @@ public class ServiceInfoTest {
String commonConfigId = "common-config-id";
String commonHostName = "common-host";
- ServiceInfo a = new ServiceInfo("0", "0", Arrays.asList(new PortInfo(33, null)), Collections.singletonMap("foo", "bar"), commonConfigId, commonHostName);
- ServiceInfo b = new ServiceInfo("0", "0", Arrays.asList(new PortInfo(33, null)), Collections.singletonMap("foo", "bar"), commonConfigId, commonHostName);
- ServiceInfo c = new ServiceInfo("0", "0", Arrays.asList(new PortInfo(33, null)), Collections.singletonMap("foo", "baz"), commonConfigId, commonHostName);
- ServiceInfo d = new ServiceInfo("0", "0", Arrays.asList(new PortInfo(33, null)), Collections.singletonMap("bar", "bar"), commonConfigId, commonHostName);
- ServiceInfo e = new ServiceInfo("0", "1", Arrays.asList(new PortInfo(33, null)), Collections.singletonMap("foo", "bar"), commonConfigId, commonHostName);
- ServiceInfo f = new ServiceInfo("1", "0", Arrays.asList(new PortInfo(33, null)), Collections.singletonMap("foo", "bar"), commonConfigId, commonHostName);
- ServiceInfo g = new ServiceInfo("1", "0", Arrays.asList(new PortInfo(33, null)), Collections.singletonMap("foo", "bar"), "different-config-id", commonHostName);
- ServiceInfo h = new ServiceInfo("1", "0", Arrays.asList(new PortInfo(33, null)), Collections.singletonMap("foo", "bar"), commonConfigId, "different-host");
+ ServiceInfo a = new ServiceInfo("0", "0", List.of(new PortInfo(33, null)), Map.of("foo", "bar"), commonConfigId, commonHostName);
+ ServiceInfo b = new ServiceInfo("0", "0", List.of(new PortInfo(33, null)), Map.of("foo", "bar"), commonConfigId, commonHostName);
+ ServiceInfo c = new ServiceInfo("0", "0", List.of(new PortInfo(33, null)), Map.of("foo", "baz"), commonConfigId, commonHostName);
+ ServiceInfo d = new ServiceInfo("0", "0", List.of(new PortInfo(33, null)), Map.of("bar", "bar"), commonConfigId, commonHostName);
+ ServiceInfo e = new ServiceInfo("0", "1", List.of(new PortInfo(33, null)), Map.of("foo", "bar"), commonConfigId, commonHostName);
+ ServiceInfo f = new ServiceInfo("1", "0", List.of(new PortInfo(33, null)), Map.of("foo", "bar"), commonConfigId, commonHostName);
+ ServiceInfo g = new ServiceInfo("1", "0", List.of(new PortInfo(33, null)), Map.of("foo", "bar"), "different-config-id", commonHostName);
+ ServiceInfo h = new ServiceInfo("1", "0", List.of(new PortInfo(33, null)), Map.of("foo", "bar"), commonConfigId, "different-host");
assertEquals(a, b);
assertNotEquals(a, c);
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpGetConfigHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpGetConfigHandlerTest.java
index 34045cf3804..452ee53c439 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpGetConfigHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpGetConfigHandlerTest.java
@@ -17,7 +17,7 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
-import java.util.Collections;
+import java.util.Map;
import static com.yahoo.jdisc.http.HttpRequest.Method.GET;
import static com.yahoo.jdisc.http.HttpResponse.Status.BAD_REQUEST;
@@ -90,7 +90,7 @@ public class HttpGetConfigHandlerTest {
@Test
public void require_that_nocache_property_works() throws IOException {
- HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Collections.singletonMap("nocache", "true"));
+ HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Map.of("nocache", "true"));
HttpResponse response = handler.handle(request);
String renderedString = SessionHandlerTest.getRenderedString(response);
assertTrue(renderedString, renderedString.startsWith(expected));
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpHandlerTest.java
index a7f86133fce..b58bca074b8 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/HttpHandlerTest.java
@@ -11,7 +11,7 @@ import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.time.Duration;
-import java.util.Collections;
+import java.util.Map;
import static org.junit.Assert.assertEquals;
@@ -39,7 +39,7 @@ public class HttpHandlerTest {
HttpRequest.createTestRequest("foo",
com.yahoo.jdisc.http.HttpRequest.Method.GET,
null,
- Collections.singletonMap("timeout", "1.5")), Duration.ofSeconds(5)).toMillis());
+ Map.of("timeout", "1.5")), Duration.ofSeconds(5)).toMillis());
}
private static class HttpTestHandler extends HttpHandler {
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java
index 6f2c7366b62..4c140159e12 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java
@@ -24,7 +24,6 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
-import java.util.Collections;
import java.util.Map;
import static com.yahoo.jdisc.Response.Status.BAD_REQUEST;
@@ -126,7 +125,7 @@ public class HttpGetConfigHandlerTest {
@Test
public void require_that_nocache_property_works() throws IOException {
- HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Collections.singletonMap("nocache", "true"));
+ HttpRequest request = HttpRequest.createTestRequest(configUri, GET, null, Map.of("nocache", "true"));
HttpResponse response = handler.handle(request);
String renderedString = SessionHandlerTest.getRenderedString(response);
assertTrue(renderedString, renderedString.startsWith(expected));
diff --git a/container-core/src/main/java/com/yahoo/processing/request/Properties.java b/container-core/src/main/java/com/yahoo/processing/request/Properties.java
index d06e8b26cd9..e689ea76f3a 100644
--- a/container-core/src/main/java/com/yahoo/processing/request/Properties.java
+++ b/container-core/src/main/java/com/yahoo/processing/request/Properties.java
@@ -3,7 +3,6 @@ package com.yahoo.processing.request;
import java.util.Map;
import java.util.HashMap;
-import java.util.Collections;
/**
* The properties of a request
@@ -271,7 +270,7 @@ public class Properties implements Cloneable {
* @throws RuntimeException if no instance in the chain accepted this name-value pair
*/
public final void clearAll(String name) {
- clearAll(new CompoundName(name), Collections.<String,String>emptyMap());
+ clearAll(new CompoundName(name), Map.of());
}
/**
diff --git a/container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.java b/container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.java
index f70772b7331..2aa5c888865 100644
--- a/container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.java
+++ b/container-core/src/test/java/com/yahoo/container/jdisc/HttpRequestTestCase.java
@@ -8,7 +8,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.Collections;
+import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -30,7 +30,7 @@ public class HttpRequestTestCase {
@BeforeEach
public void setUp() throws Exception {
requestData = new ByteArrayInputStream(Utf8.toBytes(X_RAY_YANKEE_ZULU));
- r = HttpRequest.createTestRequest(HTTP_MAILHOST_25_ALPHA_BRAVO_CHARLIE_DELTA, Method.GET, requestData, Collections.singletonMap("foxtrot", "golf"));
+ r = HttpRequest.createTestRequest(HTTP_MAILHOST_25_ALPHA_BRAVO_CHARLIE_DELTA, Method.GET, requestData, Map.of("foxtrot", "golf"));
}
@AfterEach
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 aacac7b5c04..822359d7c09 100644
--- a/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerAllMessageTypesTestCase.java
+++ b/docproc/src/test/java/com/yahoo/docproc/jdisc/DocumentProcessingHandlerAllMessageTypesTestCase.java
@@ -25,9 +25,8 @@ import com.yahoo.messagebus.Reply;
import org.junit.Test;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
@@ -48,7 +47,7 @@ public class DocumentProcessingHandlerAllMessageTypesTestCase extends DocumentPr
this.type.addField(new Field("blahblah", DataType.STRING));
this.type.addField(new Field("defaultWait", DataType.INT));
this.type.addField(new Field("customWait", DataType.INT));
- type.addFieldSets(Collections.singletonMap(DocumentType.DOCUMENT, Arrays.asList("blahblah", "defaultWait", "customWait")));
+ type.addFieldSets(Map.of(DocumentType.DOCUMENT, List.of("blahblah", "defaultWait", "customWait")));
}
@Test
@@ -158,8 +157,7 @@ public class DocumentProcessingHandlerAllMessageTypesTestCase extends DocumentPr
Document doc = ((DocumentPut) op).getDocument();
for (Field f : doc.getDataType().fieldSet()) {
FieldValue val = doc.getFieldValue(f);
- if (val instanceof StringFieldValue) {
- StringFieldValue sf = (StringFieldValue) val;
+ if (val instanceof StringFieldValue sf) {
doc.setFieldValue(f, new StringFieldValue(sf.getString().toUpperCase()));
}
}
diff --git a/document/src/test/java/com/yahoo/document/DocumentTypeTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTypeTestCase.java
index 5f8e95a2b4f..17d1d745f6a 100644
--- a/document/src/test/java/com/yahoo/document/DocumentTypeTestCase.java
+++ b/document/src/test/java/com/yahoo/document/DocumentTypeTestCase.java
@@ -3,15 +3,14 @@ package com.yahoo.document;
import org.junit.Test;
-import java.util.Arrays;
-import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
+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.assertNull;
-import static org.junit.Assert.assertTrue;
/**
* @author Thomas Gundersen
@@ -37,7 +36,7 @@ public class DocumentTypeTestCase {
root.addField("rootfield1", DataType.STRING);
root.addField("rootfield2", DataType.STRING);
root.addField("rootfield3", DataType.STRING);
- root.addFieldSets(Collections.singletonMap(DocumentType.DOCUMENT, Arrays.asList("rootfield2")));
+ root.addFieldSets(Map.of(DocumentType.DOCUMENT, List.of("rootfield2")));
assertEquals(1, root.fieldSet().size());
assertEquals("rootfield2", root.fieldSet().iterator().next().getName());
assertEquals(3, root.fieldSetAll().size());
@@ -49,25 +48,25 @@ public class DocumentTypeTestCase {
DocumentType root = new DocumentType("root");
root.addField("rootfield", DataType.STRING);
- root.addFieldSets(Collections.singletonMap(DocumentType.DOCUMENT, Arrays.asList("rootfield")));
+ root.addFieldSets(Map.of(DocumentType.DOCUMENT, List.of("rootfield")));
DocumentType parent1 = new DocumentType("parent1");
parent1.addField("overridden", DataType.STRING);
parent1.addField("parent1field", DataType.STRING);
parent1.inherit(root);
- parent1.addFieldSets(Collections.singletonMap(DocumentType.DOCUMENT, Arrays.asList("parent1field", "overridden")));
+ parent1.addFieldSets(Map.of(DocumentType.DOCUMENT, List.of("parent1field", "overridden")));
DocumentType parent2 = new DocumentType("parent2");
parent2.addField("parent2field", DataType.STRING);
parent2.inherit(root);
- parent2.addFieldSets(Collections.singletonMap(DocumentType.DOCUMENT, Arrays.asList("parent2field")));
+ parent2.addFieldSets(Map.of(DocumentType.DOCUMENT, List.of("parent2field")));
DocumentType child = new DocumentType("child");
child.addField("childfield", DataType.INT);
child.addField("overridden", DataType.STRING);
child.inherit(parent1);
child.inherit(parent2);
- child.addFieldSets(Collections.singletonMap(DocumentType.DOCUMENT, Arrays.asList("childfield", "overridden")));
+ child.addFieldSets(Map.of(DocumentType.DOCUMENT, List.of("childfield", "overridden")));
typeManager.register(root);
typeManager.register(parent1);
@@ -77,19 +76,19 @@ public class DocumentTypeTestCase {
Iterator inherited = child.getInheritedTypes().iterator();
assertEquals(parent1, inherited.next());
assertEquals(parent2, inherited.next());
- assertTrue(!inherited.hasNext());
+ assertFalse(inherited.hasNext());
inherited = parent1.getInheritedTypes().iterator();
assertEquals(root, inherited.next());
- assertTrue(!inherited.hasNext());
+ assertFalse(inherited.hasNext());
inherited = parent2.getInheritedTypes().iterator();
assertEquals(root, inherited.next());
- assertTrue(!inherited.hasNext());
+ assertFalse(inherited.hasNext());
inherited = root.getInheritedTypes().iterator();
assertEquals(DataType.DOCUMENT, inherited.next());
- assertTrue(!inherited.hasNext());
+ assertFalse(inherited.hasNext());
Iterator fields = child.fieldSet().iterator();
Field field;
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionConverterTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionConverterTestCase.java
index 72a03e938fb..52a015137aa 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionConverterTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionConverterTestCase.java
@@ -55,7 +55,6 @@ import com.yahoo.vespa.indexinglanguage.expressions.ZCurveExpression;
import com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig;
import org.junit.Test;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -109,7 +108,7 @@ public class ExpressionConverterTestCase {
assertConvertable(new StatementExpression(new InputExpression("foo")));
assertConvertable(new SubstringExpression(6, 9));
assertConvertable(new SummaryExpression("foo"));
- assertConvertable(new SwitchExpression(Collections.singletonMap("foo", (Expression)new IndexExpression("bar")),
+ assertConvertable(new SwitchExpression(Map.of("foo", (Expression)new IndexExpression("bar")),
new InputExpression("baz")));
assertConvertable(new ThisExpression());
assertConvertable(new ToArrayExpression());
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionSearcherTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionSearcherTestCase.java
index 4a8348204a6..c4f71402afa 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionSearcherTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionSearcherTestCase.java
@@ -17,8 +17,8 @@ import com.yahoo.vespa.indexinglanguage.expressions.StatementExpression;
import com.yahoo.vespa.indexinglanguage.expressions.SwitchExpression;
import org.junit.Test;
-import java.util.Arrays;
-import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -67,18 +67,18 @@ public class ExpressionSearcherTestCase {
assertFound(exp, new ScriptExpression(new StatementExpression(new AttributeExpression("foo")),
new StatementExpression(exp)));
assertFound(exp, new SelectInputExpression(
- Arrays.asList(new Pair<String, Expression>("foo", exp),
- new Pair<String, Expression>("bar", new AttributeExpression("bar")))));
+ List.of(new Pair<>("foo", exp),
+ new Pair<>("bar", new AttributeExpression("bar")))));
assertFound(exp, new SelectInputExpression(
- Arrays.asList(new Pair<String, Expression>("foo", new AttributeExpression("bar")),
- new Pair<String, Expression>("bar", exp))));
+ List.of(new Pair<>("foo", new AttributeExpression("bar")),
+ new Pair<>("bar", exp))));
assertFound(exp, new StatementExpression(exp));
assertFound(exp, new StatementExpression(new AttributeExpression("foo"), exp));
assertFound(exp, new SwitchExpression(
- Collections.singletonMap("foo", exp),
+ Map.of("foo", exp),
new AttributeExpression("bar")));
assertFound(exp, new SwitchExpression(
- Collections.singletonMap("foo", new AttributeExpression("bar")),
+ Map.of("foo", new AttributeExpression("bar")),
exp));
}
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionVisitorTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionVisitorTestCase.java
index 5bbf62bfff7..de512997b64 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionVisitorTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/ExpressionVisitorTestCase.java
@@ -55,7 +55,8 @@ import com.yahoo.vespa.indexinglanguage.expressions.ZCurveExpression;
import com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig;
import org.junit.Test;
-import java.util.Collections;
+
+import java.util.Map;
import static org.junit.Assert.assertEquals;
@@ -64,7 +65,6 @@ import static org.junit.Assert.assertEquals;
*/
public class ExpressionVisitorTestCase {
- @SuppressWarnings("unchecked")
@Test
public void requireThatAllExpressionsAreVisited() {
assertCount(3, new ArithmeticExpression(new InputExpression("foo"), ArithmeticExpression.Operator.ADD,
@@ -96,8 +96,8 @@ public class ExpressionVisitorTestCase {
assertCount(2, new ParenthesisExpression(new InputExpression("foo")));
assertCount(1, new RandomExpression(69));
assertCount(3, new ScriptExpression(new StatementExpression(new InputExpression("foo"))));
- assertCount(3, new SelectInputExpression(new Pair<String, Expression>("foo", new IndexExpression("bar")),
- new Pair<String, Expression>("bar", new IndexExpression("foo"))));
+ assertCount(3, new SelectInputExpression(new Pair<>("foo", new IndexExpression("bar")),
+ new Pair<>("bar", new IndexExpression("foo"))));
assertCount(1, new SetLanguageExpression());
assertCount(1, new ConstantExpression(new IntegerFieldValue(69)));
assertCount(1, new SetVarExpression("foo"));
@@ -105,7 +105,7 @@ public class ExpressionVisitorTestCase {
assertCount(2, new StatementExpression(new InputExpression("foo")));
assertCount(1, new SummaryExpression("foo"));
assertCount(1, new SubstringExpression(6, 9));
- assertCount(3, new SwitchExpression(Collections.singletonMap("foo", (Expression)new IndexExpression("bar")),
+ assertCount(3, new SwitchExpression(Map.of("foo", (Expression)new IndexExpression("bar")),
new InputExpression("baz")));
assertCount(1, new ThisExpression());
assertCount(1, new ToArrayExpression());
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java
index 62d333e356f..376677b6f57 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/expressions/SwitchTestCase.java
@@ -7,7 +7,6 @@ import com.yahoo.document.datatypes.IntegerFieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import org.junit.Test;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -45,10 +44,10 @@ public class SwitchTestCase {
cases.put("bar", bar);
SwitchExpression exp = new SwitchExpression(cases, baz);
- assertFalse(exp.equals(new Object()));
- assertFalse(exp.equals(new SwitchExpression(Collections.singletonMap("foo", foo))));
- assertFalse(exp.equals(new SwitchExpression(Collections.singletonMap("foo", foo), baz)));
- assertFalse(exp.equals(new SwitchExpression(cases)));
+ assertNotEquals(exp, new Object());
+ assertNotEquals(exp, new SwitchExpression(Map.of("foo", foo)));
+ assertNotEquals(exp, new SwitchExpression(Map.of("foo", foo), baz));
+ assertNotEquals(exp, new SwitchExpression(cases));
assertEquals(exp, new SwitchExpression(cases, baz));
assertEquals(exp.hashCode(), new SwitchExpression(cases, baz).hashCode());
}
@@ -56,7 +55,7 @@ public class SwitchTestCase {
@Test
public void requireThatExpressionCanBeVerified() {
Expression foo = SimpleExpression.newConversion(DataType.STRING, DataType.INT);
- Expression exp = new SwitchExpression(Collections.singletonMap("foo", foo));
+ Expression exp = new SwitchExpression(Map.of("foo", foo));
assertVerify(DataType.STRING, exp, DataType.STRING); // does not touch output
assertVerifyThrows(null, exp, "Expected string input, but no input is specified");
assertVerifyThrows(DataType.INT, exp, "Expected string input, got int");
@@ -68,15 +67,14 @@ public class SwitchTestCase {
cases.put("foo", SimpleExpression.newRequired(DataType.INT));
assertVerifyThrows(DataType.STRING, new SwitchExpression(cases),
"Expected int input, got string");
- assertVerifyThrows(DataType.STRING, new SwitchExpression(Collections.<String, Expression>emptyMap(),
- SimpleExpression.newRequired(DataType.INT)),
+ assertVerifyThrows(DataType.STRING, new SwitchExpression(Map.of(), SimpleExpression.newRequired(DataType.INT)),
"Expected int input, got string");
}
@Test
public void requireThatIllegalArgumentThrows() {
try {
- new SwitchExpression(Collections.<String, Expression>emptyMap()).execute(new IntegerFieldValue(69));
+ new SwitchExpression(Map.of()).execute(new IntegerFieldValue(69));
fail();
} catch (IllegalArgumentException e) {
assertEquals("Expected string input, got int", e.getMessage());
@@ -85,18 +83,18 @@ public class SwitchTestCase {
@Test
public void requireThatDefaultExpressionIsNullIfNotGiven() {
- assertNull(new SwitchExpression(Collections.<String, Expression>emptyMap()).getDefaultExpression());
+ assertNull(new SwitchExpression(Map.of()).getDefaultExpression());
}
@Test
public void requireThatIsEmptyReflectsOnBothCasesAndDefault() {
- assertTrue(new SwitchExpression(Collections.<String, Expression>emptyMap()).isEmpty());
- assertTrue(new SwitchExpression(Collections.<String, Expression>emptyMap(), null).isEmpty());
- assertFalse(new SwitchExpression(Collections.<String, Expression>emptyMap(),
+ assertTrue(new SwitchExpression(Map.of()).isEmpty());
+ assertTrue(new SwitchExpression(Map.of(), null).isEmpty());
+ assertFalse(new SwitchExpression(Map.of(),
new AttributeExpression("foo")).isEmpty());
- assertFalse(new SwitchExpression(Collections.singletonMap("foo", new AttributeExpression("foo")),
+ assertFalse(new SwitchExpression(Map.of("foo", new AttributeExpression("foo")),
null).isEmpty());
- assertFalse(new SwitchExpression(Collections.singletonMap("foo", new AttributeExpression("foo")),
+ assertFalse(new SwitchExpression(Map.of("foo", new AttributeExpression("foo")),
new AttributeExpression("foo")).isEmpty());
}
diff --git a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/linguistics/LinguisticsAnnotatorTestCase.java b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/linguistics/LinguisticsAnnotatorTestCase.java
index fecb89ee167..136e71564d8 100644
--- a/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/linguistics/LinguisticsAnnotatorTestCase.java
+++ b/indexinglanguage/src/test/java/com/yahoo/vespa/indexinglanguage/linguistics/LinguisticsAnnotatorTestCase.java
@@ -18,7 +18,9 @@ import com.yahoo.language.simple.SimpleToken;
import org.junit.Test;
import org.mockito.Mockito;
-import java.util.*;
+
+import java.util.List;
+import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -90,7 +92,7 @@ public class LinguisticsAnnotatorTestCase {
public void requireThatTermAnnotationsAreEmptyIfOrigIsLowerCase() {
SpanTree expected = new SpanTree(SpanTrees.LINGUISTICS);
expected.spanList().span(0, 3).annotate(new Annotation(AnnotationTypes.TERM));
- for (boolean specialToken : Arrays.asList(true, false)) {
+ for (boolean specialToken : List.of(true, false)) {
for (TokenType type : TokenType.values()) {
if (!specialToken && !type.isIndexable()) {
continue;
@@ -104,7 +106,7 @@ public class LinguisticsAnnotatorTestCase {
public void requireThatTermAnnotationsPreserveCasing() {
SpanTree expected = new SpanTree(SpanTrees.LINGUISTICS);
expected.spanList().span(0, 3).annotate(new Annotation(AnnotationTypes.TERM, new StringFieldValue("BaR")));
- for (boolean specialToken : Arrays.asList(true, false)) {
+ for (boolean specialToken : List.of(true, false)) {
for (TokenType type : TokenType.values()) {
if (!specialToken && !type.isIndexable()) {
continue;
@@ -153,7 +155,7 @@ public class LinguisticsAnnotatorTestCase {
public void requireThatTermReplacementsAreApplied() {
SpanTree expected = new SpanTree(SpanTrees.LINGUISTICS);
expected.spanList().span(0, 3).annotate(new Annotation(AnnotationTypes.TERM, new StringFieldValue("bar")));
- for (boolean specialToken : Arrays.asList(true, false)) {
+ for (boolean specialToken : List.of(true, false)) {
for (TokenType type : TokenType.values()) {
if (!specialToken && !type.isIndexable()) {
continue;
@@ -161,7 +163,7 @@ public class LinguisticsAnnotatorTestCase {
assertAnnotations(expected, "foo",
new AnnotatorConfig(),
newLinguistics(List.of(token("foo", "foo", type, specialToken)),
- Collections.singletonMap("foo", "bar")));
+ Map.of("foo", "bar")));
}
}
}
@@ -175,7 +177,7 @@ public class LinguisticsAnnotatorTestCase {
val.setSpanTree(spanTree);
Linguistics linguistics = newLinguistics(List.of(token("foo", "bar", TokenType.ALPHABETIC, false)),
- Collections.<String, String>emptyMap());
+ Map.of());
assertTrue(new LinguisticsAnnotator(linguistics, new AnnotatorConfig()).annotate(val));
assertEquals(spanTree, val.getSpanTree(SpanTrees.LINGUISTICS));
}
@@ -244,11 +246,11 @@ public class LinguisticsAnnotatorTestCase {
}
private static void assertAnnotations(SpanTree expected, String value, Token... tokens) {
- assertAnnotations(expected, value, new AnnotatorConfig(), newLinguistics(Arrays.asList(tokens), Map.of()));
+ assertAnnotations(expected, value, new AnnotatorConfig(), newLinguistics(List.of(tokens), Map.of()));
}
private static void assertAnnotations(SpanTree expected, String value, AnnotatorConfig config, Token... tokens) {
- assertAnnotations(expected, value, config, newLinguistics(Arrays.asList(tokens), Map.of()));
+ assertAnnotations(expected, value, config, newLinguistics(List.of(tokens), Map.of()));
}
private static void assertAnnotations(SpanTree expected, String str, AnnotatorConfig config, Linguistics linguistics) {
@@ -272,9 +274,12 @@ public class LinguisticsAnnotatorTestCase {
}
private Token replace(Token token, Map<String, String> replacementTerms) {
- var simpleToken = (SimpleToken)token;
- simpleToken.setTokenString(replacementTerms.getOrDefault(token.getTokenString(), token.getTokenString()));
- return simpleToken;
+ String tokenString = token.getTokenString();
+ if (tokenString != null && !replacementTerms.isEmpty()) {
+ var simpleToken = (SimpleToken)token;
+ simpleToken.setTokenString(replacementTerms.getOrDefault(token.getTokenString(), token.getTokenString()));
+ }
+ return token;
}
@Override
diff --git a/vespajlib/src/test/java/com/yahoo/collections/LazyMapTest.java b/vespajlib/src/test/java/com/yahoo/collections/LazyMapTest.java
index 940dc159a17..930b274ef3e 100644
--- a/vespajlib/src/test/java/com/yahoo/collections/LazyMapTest.java
+++ b/vespajlib/src/test/java/com/yahoo/collections/LazyMapTest.java
@@ -4,7 +4,6 @@ package com.yahoo.collections;
import org.junit.Test;
import org.mockito.Mockito;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -22,7 +21,6 @@ import static org.junit.Assert.fail;
* @author Simon Thoresen Hult
*/
public class LazyMapTest {
-
@Test
public void requireThatInitialDelegateIsEmpty() {
LazyMap<String, String> map = newLazyMap(new HashMap<String, String>());
@@ -36,14 +34,14 @@ public class LazyMapTest {
assertEquals(LazyMap.SingletonMap.class, map.getDelegate().getClass());
map = newLazyMap(new HashMap<String, String>());
- map.putAll(Collections.singletonMap("foo", "bar"));
+ map.put("foo", "bar");
assertEquals(LazyMap.SingletonMap.class, map.getDelegate().getClass());
}
@Test
public void requireThatEmptyMapPutAllEmptyMapDoesNotUpgradeToSingletonMap() {
LazyMap<String, String> map = newLazyMap(new HashMap<String, String>());
- map.putAll(Collections.<String, String>emptyMap());
+ map.putAll(Map.of());
assertEquals(LazyMap.EmptyMap.class, map.getDelegate().getClass());
}
@@ -81,7 +79,7 @@ public class LazyMapTest {
assertEquals("bar", map.put("foo", "baz"));
assertEquals("baz", map.get("foo"));
assertSame(delegate, map.getDelegate());
- map.putAll(Collections.singletonMap("foo", "cox"));
+ map.put("foo", "cox");
assertSame(delegate, map.getDelegate());
assertEquals("cox", map.get("foo"));
}
@@ -89,7 +87,7 @@ public class LazyMapTest {
@Test
public void requireThatSingletonMapPutAllEmptyMapDoesNotUpgradeToFinalMap() {
LazyMap<String, String> map = newSingletonMap("foo", "bar");
- map.putAll(Collections.<String, String>emptyMap());
+ map.putAll(Map.of());
assertEquals(LazyMap.SingletonMap.class, map.getDelegate().getClass());
}
@@ -188,7 +186,7 @@ public class LazyMapTest {
Mockito.verify(delegate).put("foo", "bar");
Mockito.verify(delegate).put("baz", "cox");
- Map<String, String> arg = Collections.singletonMap("baz", "cox");
+ Map<String, String> arg = Map.of("baz", "cox");
map.putAll(arg);
Mockito.verify(delegate).putAll(arg);