summaryrefslogtreecommitdiffstats
path: root/container-core/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-06-29 20:42:15 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2022-06-29 20:42:15 +0200
commit90a9f7a3ccf1f29bd1e3ced4368e373dd1193fd8 (patch)
tree25317b7e331fc937600db66f9957c004173585a0 /container-core/src
parent0ea6bd254a9b0efc986055431ce9eefc7c63840c (diff)
Join 2 testcases for CompoundName.
Stricter testcase for CompoundName, to also test internals. Fix single value append.
Diffstat (limited to 'container-core/src')
-rw-r--r--container-core/src/main/java/com/yahoo/processing/request/CompoundName.java14
-rw-r--r--container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java121
-rw-r--r--container-core/src/test/java/com/yahoo/processing/request/test/CompoundNameTestCase.java66
3 files changed, 97 insertions, 104 deletions
diff --git a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
index 205352c4d49..19a82ef56d7 100644
--- a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
+++ b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
@@ -2,6 +2,7 @@
package com.yahoo.processing.request;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import static com.yahoo.text.Lowercase.toLowerCase;
@@ -86,7 +87,8 @@ public final class CompoundName {
}
}
if (p == 0) {
- return List.of(s);
+ if (l == null) return List.of(s);
+ l.add(s);
} else if (p < m) {
l.add(s.substring(p, m));
} else {
@@ -135,7 +137,7 @@ public final class CompoundName {
if (isEmpty()) return fromComponents(nameParts);
List<String> newCompounds = new ArrayList<>(nameParts.length + compounds.size());
- newCompounds.addAll(List.of(nameParts));
+ newCompounds.addAll(Arrays.asList(nameParts));
newCompounds.addAll(this.compounds);
return new CompoundName(newCompounds);
}
@@ -255,11 +257,9 @@ public final class CompoundName {
public int hashCode() { return hashCode; }
@Override
- public boolean equals(Object o) {
- if (o == this) return true;
- if ( ! (o instanceof CompoundName)) return false;
- CompoundName other = (CompoundName)o;
- return this.name.equals(other.name);
+ public boolean equals(Object arg) {
+ if (arg == this) return true;
+ return (arg instanceof CompoundName o) && name.equals(o.name);
}
/**
diff --git a/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java b/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java
index 841866f1e83..a8a2c76a609 100644
--- a/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java
+++ b/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java
@@ -1,17 +1,17 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.processing.request;
-
-import static org.junit.Assert.*;
+import com.google.common.base.Splitter;
+import com.yahoo.text.Lowercase;
import java.util.Iterator;
import java.util.List;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import com.google.common.base.Splitter;
-import com.yahoo.text.Lowercase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
/**
* Module local test of the basic property name building block.
@@ -21,17 +21,15 @@ import com.yahoo.text.Lowercase;
public class CompoundNameTestCase {
private static final String NAME = "com.yahoo.processing.request.CompoundNameTestCase";
- private CompoundName cn;
+ private final CompoundName cn = new CompoundName(NAME);
- @Before
- public void setUp() throws Exception {
- cn = new CompoundName(NAME);
+ void verifyStrict(CompoundName expected, CompoundName actual) {
+ assertEquals(expected, actual);
+ assertEquals(expected.asList(), actual.asList());
}
-
- @After
- public void tearDown() throws Exception {
+ void verifyStrict(String expected, CompoundName actual) {
+ verifyStrict(new CompoundName(expected), actual);
}
-
@Test
public final void testLast() {
assertEquals(NAME.substring(NAME.lastIndexOf('.') + 1), cn.last());
@@ -44,17 +42,17 @@ public class CompoundNameTestCase {
@Test
public final void testRest() {
- assertEquals(NAME.substring(NAME.indexOf('.') + 1), cn.rest().toString());
+ verifyStrict(NAME.substring(NAME.indexOf('.') + 1), cn.rest());
}
@Test
public final void testRestN() {
- assertEquals("a.b.c.d.e", new CompoundName("a.b.c.d.e").rest(0).toString());
- assertEquals("b.c.d.e", new CompoundName("a.b.c.d.e").rest(1).toString());
- assertEquals("c.d.e", new CompoundName("a.b.c.d.e").rest(2).toString());
- assertEquals("d.e", new CompoundName("a.b.c.d.e").rest(3).toString());
- assertEquals("e", new CompoundName("a.b.c.d.e").rest(4).toString());
- assertEquals("", new CompoundName("a.b.c.d.e").rest(5).toString());
+ verifyStrict("a.b.c.d.e", new CompoundName("a.b.c.d.e").rest(0));
+ verifyStrict("b.c.d.e", new CompoundName("a.b.c.d.e").rest(1));
+ verifyStrict("c.d.e", new CompoundName("a.b.c.d.e").rest(2));
+ verifyStrict("d.e", new CompoundName("a.b.c.d.e").rest(3));
+ verifyStrict("e", new CompoundName("a.b.c.d.e").rest(4));
+ verifyStrict(CompoundName.empty, new CompoundName("a.b.c.d.e").rest(5));
}
@Test
@@ -69,6 +67,12 @@ public class CompoundNameTestCase {
}
@Test
+ public void testFromComponents() {
+ verifyStrict("a", CompoundName.fromComponents("a"));
+ verifyStrict("a.b", CompoundName.fromComponents("a", "b"));
+ }
+
+ @Test
public final void testSize() {
Splitter s = Splitter.on('.');
Iterable<String> i = s.split(NAME);
@@ -111,8 +115,8 @@ public class CompoundNameTestCase {
public final void testEqualsObject() {
assertFalse(cn.equals(NAME));
assertFalse(cn.equals(null));
- assertTrue(cn.equals(cn));
- assertTrue(cn.equals(new CompoundName(NAME)));
+ verifyStrict(cn, cn);
+ verifyStrict(cn, new CompoundName(NAME));
}
@Test
@@ -122,8 +126,8 @@ public class CompoundNameTestCase {
assertFalse(new CompoundName("a").isEmpty());
assertEquals(1, new CompoundName("a").size());
CompoundName empty = new CompoundName("a.b.c");
- assertTrue(empty == empty.rest(0));
- assertFalse(empty == empty.rest(1));
+ verifyStrict(empty, empty.rest(0));
+ assertNotEquals(empty, empty.rest(1));
}
@Test
@@ -132,12 +136,12 @@ public class CompoundNameTestCase {
}
@Test
- public void testAppend() {
- assertEquals(new CompoundName("a.b.c.d"), new CompoundName("").append(new CompoundName("a.b.c.d")));
- assertEquals(new CompoundName("a.b.c.d"), new CompoundName("a").append(new CompoundName("b.c.d")));
- assertEquals(new CompoundName("a.b.c.d"), new CompoundName("a.b").append(new CompoundName("c.d")));
- assertEquals(new CompoundName("a.b.c.d"), new CompoundName("a.b.c").append(new CompoundName("d")));
- assertEquals(new CompoundName("a.b.c.d"), new CompoundName("a.b.c.d").append(new CompoundName("")));
+ public void testAppendCompound() {
+ verifyStrict("a.b.c.d", new CompoundName("").append(new CompoundName("a.b.c.d")));
+ verifyStrict("a.b.c.d", new CompoundName("a").append(new CompoundName("b.c.d")));
+ verifyStrict("a.b.c.d", new CompoundName("a.b").append(new CompoundName("c.d")));
+ verifyStrict("a.b.c.d", new CompoundName("a.b.c").append(new CompoundName("d")));
+ verifyStrict("a.b.c.d", new CompoundName("a.b.c.d").append(new CompoundName("")));
}
@Test
@@ -155,4 +159,59 @@ public class CompoundNameTestCase {
assertFalse(name.hasPrefix(stringPrefix));
}
+
+ @Test
+ public void testFirstRest() {
+ verifyStrict(CompoundName.empty, CompoundName.empty.rest());
+
+ CompoundName n=new CompoundName("on.two.three");
+ assertEquals("on", n.first());
+ verifyStrict("two.three", n.rest());
+ n=n.rest();
+ assertEquals("two", n.first());
+ verifyStrict("three", n.rest());
+ n=n.rest();
+ assertEquals("three", n.first());
+ verifyStrict("", n.rest());
+ n=n.rest();
+ assertEquals("", n.first());
+ verifyStrict("", n.rest());
+ n=n.rest();
+ assertEquals("", n.first());
+ verifyStrict("", n.rest());
+ }
+
+ @Test
+ public void testHashCodeAndEquals() {
+ CompoundName n1 = new CompoundName("venn.d.a");
+ CompoundName n2 = new CompoundName(n1.asList());
+ assertEquals(n1.hashCode(), n2.hashCode());
+ verifyStrict(n1, n2);
+ }
+
+ @Test
+ public void testAppendString() {
+ verifyStrict("a", new CompoundName("a").append(""));
+ verifyStrict("a", new CompoundName("").append("a"));
+ verifyStrict("a.b", new CompoundName("a").append("b"));
+ verifyStrict("a.b.c.d", new CompoundName("a.b").append("c.d"));
+
+ CompoundName name = new CompoundName("a.b");
+ verifyStrict("a.b.c", name.append("c"));
+ verifyStrict("a.b.d", name.append("d"));
+ verifyStrict("a.b.d.e", name.append("d.e"));
+ }
+
+ @Test
+ public void testEmpty() {
+ CompoundName empty=new CompoundName("");
+ assertEquals("", empty.toString());
+ assertEquals(0, empty.asList().size());
+ }
+
+ @Test
+ public void testAsList2() {
+ assertEquals("[one]", new CompoundName("one").asList().toString());
+ assertEquals("[one, two, three]", new CompoundName("one.two.three").asList().toString());
+ }
}
diff --git a/container-core/src/test/java/com/yahoo/processing/request/test/CompoundNameTestCase.java b/container-core/src/test/java/com/yahoo/processing/request/test/CompoundNameTestCase.java
deleted file mode 100644
index df9e77938a6..00000000000
--- a/container-core/src/test/java/com/yahoo/processing/request/test/CompoundNameTestCase.java
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.processing.request.test;
-
-import com.yahoo.processing.request.CompoundName;
-import static org.junit.Assert.assertEquals;
-import org.junit.Test;
-
-/**
- * @author bratseth
- */
-public class CompoundNameTestCase {
-
- @Test
- public void testFirstRest() {
- assertEquals(CompoundName.empty, CompoundName.empty.rest());
-
- CompoundName n=new CompoundName("on.two.three");
- assertEquals("on", n.first());
- assertEquals("two.three", n.rest().toString());
- n=n.rest();
- assertEquals("two", n.first());
- assertEquals("three", n.rest().toString());
- n=n.rest();
- assertEquals("three", n.first());
- assertEquals("", n.rest().toString());
- n=n.rest();
- assertEquals("", n.first());
- assertEquals("", n.rest().toString());
- n=n.rest();
- assertEquals("", n.first());
- assertEquals("", n.rest().toString());
- }
-
- @Test
- public void testHashCodeAndEquals() {
- CompoundName n1 = new CompoundName("venn.d.a");
- CompoundName n2 = new CompoundName(n1.asList());
- assertEquals(n1.hashCode(), n2.hashCode());
- assertEquals(n1, n2);
- }
-
- @Test
- public void testAppend() {
- assertEquals("a",new CompoundName("a").append("").toString());
- assertEquals("a",new CompoundName("").append("a").toString());
- assertEquals("a.b",new CompoundName("a").append("b").toString());
-
- CompoundName name = new CompoundName("a.b");
- assertEquals("a.b.c",name.append("c").toString());
- assertEquals("a.b.d",name.append("d").toString());
- }
-
- @Test
- public void testEmpty() {
- CompoundName empty=new CompoundName("");
- assertEquals("", empty.toString());
- assertEquals(0, empty.asList().size());
- }
-
- @Test
- public void testAsList() {
- assertEquals("[one]", new CompoundName("one").asList().toString());
- assertEquals("[one, two, three]", new CompoundName("one.two.three").asList().toString());
- }
-
-}