diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-06-29 20:42:15 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-06-29 20:42:15 +0200 |
commit | 90a9f7a3ccf1f29bd1e3ced4368e373dd1193fd8 (patch) | |
tree | 25317b7e331fc937600db66f9957c004173585a0 /container-core/src/test/java/com/yahoo | |
parent | 0ea6bd254a9b0efc986055431ce9eefc7c63840c (diff) |
Join 2 testcases for CompoundName.
Stricter testcase for CompoundName, to also test internals.
Fix single value append.
Diffstat (limited to 'container-core/src/test/java/com/yahoo')
-rw-r--r-- | container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java | 121 | ||||
-rw-r--r-- | container-core/src/test/java/com/yahoo/processing/request/test/CompoundNameTestCase.java | 66 |
2 files changed, 90 insertions, 97 deletions
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()); - } - -} |