diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-20 18:38:08 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-21 01:18:09 +0100 |
commit | e8f31cbe437ee969f4dd0490a0409b62b2fd045d (patch) | |
tree | 694203ae0423448b259c924c167ecb5584c36229 /vespajlib/src/test | |
parent | 5d6f586ccff9880a40366d51f75db5234795c0fc (diff) |
GC deprecated junit assertThat.
Diffstat (limited to 'vespajlib/src/test')
16 files changed, 168 insertions, 287 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/collections/HashletTestCase.java b/vespajlib/src/test/java/com/yahoo/collections/HashletTestCase.java index 59f0583cbd4..ddee8147acd 100644 --- a/vespajlib/src/test/java/com/yahoo/collections/HashletTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/collections/HashletTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.collections; import org.junit.Test; -import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; public class HashletTestCase { @@ -12,14 +11,14 @@ public class HashletTestCase { public void testCopyEmptyHashlet() { Hashlet<String, Integer> hash = new Hashlet<>(); Hashlet<String, Integer> hash2 = new Hashlet<>(hash); - assertThat(hash.size(), is(0)); - assertThat(hash2.size(), is(0)); + assertEquals(0, hash.size()); + assertEquals(0, hash2.size()); hash.put("foo", 5); hash2.put("bar", 7); - assertThat(hash.get("foo"), is(5)); - assertThat(hash.get("bar"), nullValue()); - assertThat(hash2.get("foo"), nullValue()); - assertThat(hash2.get("bar"), is(7)); + assertEquals(5, hash.get("foo").intValue()); + assertNull(hash.get("bar")); + assertNull(hash2.get("foo")); + assertEquals(7, hash2.get("bar").intValue()); } private void verifyEquals(Object a, Object b) { @@ -112,17 +111,17 @@ public class HashletTestCase { hash.put("foo", 5); hash.put("bar", 7); Hashlet<String, Integer> hash2 = new Hashlet<>(hash); - assertThat(hash2.size(), is(2)); - assertThat(hash2.get("foo"), is(5)); - assertThat(hash2.get("bar"), is(7)); - assertThat(hash2.key(0), is("foo")); - assertThat(hash2.key(1), is("bar")); - assertThat(hash2.value(0), is(5)); - assertThat(hash2.value(1), is(7)); - assertThat(hash2.key(0), sameInstance(hash.key(0))); - assertThat(hash2.key(1), sameInstance(hash.key(1))); - assertThat(hash2.value(0), sameInstance(hash.value(0))); - assertThat(hash2.value(1), sameInstance(hash.value(1))); + assertEquals(2, hash2.size()); + assertEquals(5, hash2.get("foo").intValue()); + assertEquals(7, hash2.get("bar").intValue()); + assertEquals("foo", hash2.key(0)); + assertEquals("bar", hash2.key(1)); + assertEquals(5, hash2.value(0).intValue()); + assertEquals(7, hash2.value(1).intValue()); + assertSame(hash2.key(0), hash.key(0)); + assertSame(hash2.key(1), hash.key(1)); + assertSame(hash2.value(0), hash.value(0)); + assertSame(hash2.value(1), hash.value(1)); } @Test @@ -130,21 +129,21 @@ public class HashletTestCase { Hashlet<String, Integer> hash = new Hashlet<>(); hash.put("foo", 5); hash.put("bar", 7); - assertThat(hash.size(), is(2)); - assertThat(hash.get("foo"), is(5)); - assertThat(hash.get("bar"), is(7)); - assertThat(hash.key(0), is("foo")); - assertThat(hash.key(1), is("bar")); - assertThat(hash.value(0), is(5)); - assertThat(hash.value(1), is(7)); + assertEquals(2, hash.size()); + assertEquals(5, hash.get("foo").intValue()); + assertEquals(7, hash.get("bar").intValue()); + assertEquals("foo", hash.key(0)); + assertEquals("bar", hash.key(1)); + assertEquals(5, hash.value(0).intValue()); + assertEquals(7, hash.value(1).intValue()); hash.put("foo", null); - assertThat(hash.size(), is(2)); - assertThat(hash.get("foo"), nullValue()); - assertThat(hash.get("bar"), is(7)); - assertThat(hash.key(0), is("foo")); - assertThat(hash.key(1), is("bar")); - assertThat(hash.value(0), nullValue()); - assertThat(hash.value(1), is(7)); + assertEquals(2, hash.size()); + assertNull(hash.get("foo")); + assertEquals(7, hash.get("bar").intValue()); + assertEquals("foo", hash.key(0)); + assertEquals("bar", hash.key(1)); + assertNull(hash.value(0)); + assertEquals(7, hash.value(1).intValue()); } @Test @@ -155,11 +154,11 @@ public class HashletTestCase { String str = ("" + i + "_str_" + i); hash.put(str, i); } - assertThat(hash.size(), is(n)); + assertEquals(n, hash.size()); for (int i = 0; i < n; i++) { String str = ("" + i + "_str_" + i); - assertThat(hash.key(i), is(str)); - assertThat(hash.value(i), is(i)); + assertEquals(str, hash.key(i)); + assertEquals(i, hash.value(i).intValue()); } } @@ -169,17 +168,17 @@ public class HashletTestCase { Hashlet<String, Integer> hash = new Hashlet<>(); for (int i = 0; i < n; i++) { String str = ("" + i + "_str_" + i); - assertThat(hash.get(str), nullValue()); + assertNull(hash.get(str)); switch (i % 2) { - case 1: assertThat(hash.put(str, i), nullValue()); + case 1: assertNull(hash.put(str, i)); } } - assertThat(hash.size(), is(n / 2)); + assertEquals(n / 2, hash.size()); for (int i = 0; i < n; i++) { String str = ("" + i + "_str_" + i); switch (i % 2) { - case 0: assertThat(hash.get(str), nullValue()); break; - case 1: assertThat(hash.get(str), is(i)); break; + case 0: assertNull(hash.get(str)); break; + case 1: assertEquals(i, hash.get(str).intValue()); break; } } } diff --git a/vespajlib/src/test/java/com/yahoo/io/TeeInputStreamTest.java b/vespajlib/src/test/java/com/yahoo/io/TeeInputStreamTest.java deleted file mode 100644 index 7b944e92d48..00000000000 --- a/vespajlib/src/test/java/com/yahoo/io/TeeInputStreamTest.java +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.io; - -import java.io.*; -import java.nio.charset.StandardCharsets; - -import org.junit.Test; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; - -/** - * @author arnej - */ -public class TeeInputStreamTest { - - @Test - public void testSimpleInput() throws IOException { - byte[] input = "very simple input".getBytes(StandardCharsets.UTF_8); - ByteArrayInputStream in = new ByteArrayInputStream(input); - ByteArrayOutputStream gotten = new ByteArrayOutputStream(); - ByteArrayOutputStream output = new ByteArrayOutputStream(); - - TeeInputStream tee = new TeeInputStream(in, gotten); - int b = tee.read(); - assertThat(b, is((int)'v')); - output.write(b); - assertThat(gotten.toString(), is("very simple input")); - for (int i = 0; i < 16; i++) { - b = tee.read(); - // System.out.println("got["+i+"]: "+(char)b); - assertThat(b, is(greaterThan(0))); - output.write(b); - } - assertThat(tee.read(), is(-1)); - assertThat(gotten.toString(), is("very simple input")); - assertThat(output.toString(), is("very simple input")); - } - - private class Generator implements Runnable { - private OutputStream dst; - public Generator(OutputStream dst) { this.dst = dst; } - @Override - public void run() { - for (int i = 0; i < 123456789; i++) { - int b = i & 0x7f; - if (b < 32) continue; - if (b > 126) b = '\n'; - try { - dst.write(b); - } catch (IOException e) { - return; - } - } - } - } - - @Test - public void testPipedInput() throws IOException { - PipedOutputStream input = new PipedOutputStream(); - PipedInputStream in = new PipedInputStream(input); - ByteArrayOutputStream gotten = new ByteArrayOutputStream(); - ByteArrayOutputStream output = new ByteArrayOutputStream(); - TeeInputStream tee = new TeeInputStream(in, gotten); - input.write("first input".getBytes(StandardCharsets.UTF_8)); - int b = tee.read(); - assertThat(b, is((int)'f')); - output.write(b); - assertThat(gotten.toString(), is("first input")); - input.write(" second input".getBytes(StandardCharsets.UTF_8)); - b = tee.read(); - assertThat(b, is((int)'i')); - output.write(b); - assertThat(gotten.toString(), is("first input second input")); - new Thread(new Generator(input)).start(); - b = tee.read(); - assertThat(b, is((int)'r')); - output.write(b); - byte[] ba = new byte[9]; - for (int i = 0; i < 12345; i++) { - b = tee.read(); - // System.out.println("got["+i+"]: "+(char)b); - assertThat(b, is(greaterThan(0))); - output.write(b); - int l = tee.read(ba); - assertThat(l, is(greaterThan(0))); - output.write(ba, 0, l); - l = tee.read(ba, 3, 3); - assertThat(l, is(greaterThan(0))); - output.write(ba, 3, l); - } - tee.close(); - String got = gotten.toString(); - // System.out.println("got length: "+got.length()); - // System.out.println("output length: "+output.toString().length()); - // System.out.println("got: "+got); - assertThat(got.length(), is(greaterThan(34567))); - assertTrue(got.startsWith(output.toString())); - } - -} diff --git a/vespajlib/src/test/java/com/yahoo/path/PathTest.java b/vespajlib/src/test/java/com/yahoo/path/PathTest.java index aa09c491586..ae4581f1e9d 100644 --- a/vespajlib/src/test/java/com/yahoo/path/PathTest.java +++ b/vespajlib/src/test/java/com/yahoo/path/PathTest.java @@ -3,9 +3,8 @@ package com.yahoo.path; import org.junit.Test; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; /** @@ -15,85 +14,85 @@ import static org.junit.Assert.assertTrue; public class PathTest { @Test public void testGetName() { - assertThat(getAbsolutePath().getName(), is("baz")); - assertThat(getRelativePath().getName(), is("baz")); - assertThat(getWithSlashes().getName(), is("baz")); - assertThat(getAppended().getName(), is("baz")); - assertThat(getOne().getName(), is("foo")); + assertEquals("baz", getAbsolutePath().getName()); + assertEquals("baz", getRelativePath().getName()); + assertEquals("baz", getWithSlashes().getName()); + assertEquals("baz", getAppended().getName()); + assertEquals("foo", getOne().getName()); } @Test public void testEquals() { - assertTrue(getAbsolutePath().equals(getAbsolutePath())); - assertTrue(getAbsolutePath().equals(getRelativePath())); - assertTrue(getAbsolutePath().equals(getWithSlashes())); - assertTrue(getAbsolutePath().equals(getAppended())); - assertFalse(getAbsolutePath().equals(getOne())); - - assertTrue(getRelativePath().equals(getAbsolutePath())); - assertTrue(getRelativePath().equals(getRelativePath())); - assertTrue(getRelativePath().equals(getWithSlashes())); - assertTrue(getRelativePath().equals(getAppended())); - assertFalse(getRelativePath().equals(getOne())); - - assertTrue(getWithSlashes().equals(getAbsolutePath())); - assertTrue(getWithSlashes().equals(getRelativePath())); - assertTrue(getWithSlashes().equals(getWithSlashes())); - assertTrue(getWithSlashes().equals(getAppended())); - assertFalse(getWithSlashes().equals(getOne())); - - assertTrue(getAppended().equals(getAbsolutePath())); - assertTrue(getAppended().equals(getRelativePath())); - assertTrue(getAppended().equals(getWithSlashes())); - assertTrue(getAppended().equals(getAppended())); - assertFalse(getAppended().equals(getOne())); - - assertFalse(getOne().equals(getAbsolutePath())); - assertFalse(getOne().equals(getRelativePath())); - assertFalse(getOne().equals(getWithSlashes())); - assertFalse(getOne().equals(getAppended())); - assertTrue(getOne().equals(getOne())); + assertEquals(getAbsolutePath(), getAbsolutePath()); + assertEquals(getAbsolutePath(), getRelativePath()); + assertEquals(getAbsolutePath(), getWithSlashes()); + assertEquals(getAbsolutePath(), getAppended()); + assertNotEquals(getAbsolutePath(), getOne()); + + assertEquals(getRelativePath(), getAbsolutePath()); + assertEquals(getRelativePath(), getRelativePath()); + assertEquals(getRelativePath(), getWithSlashes()); + assertEquals(getRelativePath(), getAppended()); + assertNotEquals(getRelativePath(), getOne()); + + assertEquals(getWithSlashes(), getAbsolutePath()); + assertEquals(getWithSlashes(), getRelativePath()); + assertEquals(getWithSlashes(), getWithSlashes()); + assertEquals(getWithSlashes(), getAppended()); + assertNotEquals(getWithSlashes(), getOne()); + + assertEquals(getAppended(), getAbsolutePath()); + assertEquals(getAppended(), getRelativePath()); + assertEquals(getAppended(), getWithSlashes()); + assertEquals(getAppended(), getAppended()); + assertNotEquals(getAppended(), getOne()); + + assertNotEquals(getOne(), getAbsolutePath()); + assertNotEquals(getOne(), getRelativePath()); + assertNotEquals(getOne(), getWithSlashes()); + assertNotEquals(getOne(), getAppended()); + assertEquals(getOne(), getOne()); } @Test public void testGetPath() { - assertThat(getAbsolutePath().getRelative(), is("foo/bar/baz")); - assertThat(getRelativePath().getRelative(), is("foo/bar/baz")); - assertThat(getWithSlashes().getRelative(), is("foo/bar/baz")); - assertThat(getAppended().getRelative(), is("foo/bar/baz")); - assertThat(getOne().getRelative(), is("foo")); + assertEquals("foo/bar/baz", getAbsolutePath().getRelative()); + assertEquals("foo/bar/baz", getRelativePath().getRelative()); + assertEquals("foo/bar/baz", getWithSlashes().getRelative()); + assertEquals("foo/bar/baz", getAppended().getRelative()); + assertEquals("foo", getOne().getRelative()); } @Test public void testGetParentPath() { - assertThat(getAbsolutePath().getParentPath().getRelative(), is("foo/bar")); - assertThat(getRelativePath().getParentPath().getRelative(), is("foo/bar")); - assertThat(getWithSlashes().getParentPath().getRelative(), is("foo/bar")); - assertThat(getAppended().getParentPath().getRelative(), is("foo/bar")); - assertThat(getOne().getParentPath().getRelative(), is("")); + assertEquals("foo/bar", getAbsolutePath().getParentPath().getRelative()); + assertEquals("foo/bar", getRelativePath().getParentPath().getRelative()); + assertEquals("foo/bar", getWithSlashes().getParentPath().getRelative()); + assertEquals("foo/bar", getAppended().getParentPath().getRelative()); + assertTrue(getOne().getParentPath().getRelative().isEmpty()); } @Test public void testGetAbsolutePath() { - assertThat(getAbsolutePath().getAbsolute(), is("/foo/bar/baz")); - assertThat(getAbsolutePath().getParentPath().getAbsolute(), is("/foo/bar")); + assertEquals("/foo/bar/baz", getAbsolutePath().getAbsolute()); + assertEquals("/foo/bar", getAbsolutePath().getParentPath().getAbsolute()); } @Test public void testEmptyPath() { - assertThat(Path.createRoot().getName(), is("")); - assertThat(Path.createRoot().getRelative(), is("")); - assertThat(Path.createRoot().getParentPath().getRelative(), is("")); + assertTrue(Path.createRoot().getName().isEmpty()); + assertTrue(Path.createRoot().getRelative().isEmpty()); + assertTrue(Path.createRoot().getParentPath().getRelative().isEmpty()); assertTrue(Path.createRoot().isRoot()); } @Test public void testDelimiters() { - assertThat(Path.fromString("foo/bar", ",").getName(), is("foo/bar")); - assertThat(Path.fromString("foo/bar", "/").getName(), is("bar")); - assertThat(Path.fromString("foo,bar", "/").getName(), is("foo,bar")); - assertThat(Path.fromString("foo,bar", ",").getName(), is("bar")); - assertThat(Path.createRoot(",").append("foo").append("bar").getRelative(), is("foo,bar")); + assertEquals("foo/bar", Path.fromString("foo/bar", ",").getName()); + assertEquals("bar", Path.fromString("foo/bar", "/").getName()); + assertEquals("foo,bar", Path.fromString("foo,bar", "/").getName()); + assertEquals("bar", Path.fromString("foo,bar", ",").getName()); + assertEquals("foo,bar", Path.createRoot(",").append("foo").append("bar").getRelative()); } @Test @@ -101,9 +100,9 @@ public class PathTest { Path p1 = getAbsolutePath(); Path p2 = getAbsolutePath(); Path p3 = p1.append(p2); - assertThat(p1.getAbsolute(), is("/foo/bar/baz")); - assertThat(p2.getAbsolute(), is("/foo/bar/baz")); - assertThat(p3.getAbsolute(), is("/foo/bar/baz/foo/bar/baz")); + assertEquals("/foo/bar/baz", p1.getAbsolute()); + assertEquals("/foo/bar/baz", p2.getAbsolute()); + assertEquals("/foo/bar/baz/foo/bar/baz", p3.getAbsolute()); } private Path getRelativePath() { diff --git a/vespajlib/src/test/java/com/yahoo/reflection/CastingTest.java b/vespajlib/src/test/java/com/yahoo/reflection/CastingTest.java index f2fa14e8958..1b781c265f4 100644 --- a/vespajlib/src/test/java/com/yahoo/reflection/CastingTest.java +++ b/vespajlib/src/test/java/com/yahoo/reflection/CastingTest.java @@ -6,9 +6,9 @@ import org.junit.Test; import java.util.Optional; import static com.yahoo.text.StringUtilities.quote; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; import static com.yahoo.reflection.Casting.cast; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; public class CastingTest { @Test @@ -16,7 +16,7 @@ public class CastingTest { Object objectToCast = 12; Optional<Integer> value = cast(Integer.class, objectToCast); assertTrue("Value is not present", value.isPresent()); - assertThat(value.get(), is(objectToCast)); + assertSame(objectToCast, value.get()); } @Test diff --git a/vespajlib/src/test/java/com/yahoo/slime/BinaryFormatTestCase.java b/vespajlib/src/test/java/com/yahoo/slime/BinaryFormatTestCase.java index 19ded5c8db1..5c3126ce3cf 100644 --- a/vespajlib/src/test/java/com/yahoo/slime/BinaryFormatTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/slime/BinaryFormatTestCase.java @@ -13,8 +13,7 @@ import static com.yahoo.slime.BinaryFormat.encode_double; import static com.yahoo.slime.BinaryFormat.encode_type_and_meta; import static com.yahoo.slime.BinaryFormat.encode_zigzag; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class BinaryFormatTestCase { diff --git a/vespajlib/src/test/java/com/yahoo/slime/JsonFormatTestCase.java b/vespajlib/src/test/java/com/yahoo/slime/JsonFormatTestCase.java index 67a11f8be5a..763f8cb221c 100644 --- a/vespajlib/src/test/java/com/yahoo/slime/JsonFormatTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/slime/JsonFormatTestCase.java @@ -2,15 +2,12 @@ package com.yahoo.slime; import com.yahoo.text.Utf8; -import org.junit.Ignore; import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -108,7 +105,7 @@ public class JsonFormatTestCase { Slime slime = new Slime(); String str = null; slime.setString(str); - assertThat(slime.get().type(), is(Type.NIX)); + assertEquals(Type.NIX, slime.get().type()); verifyEncoding(slime, "null"); } @@ -117,7 +114,7 @@ public class JsonFormatTestCase { Slime slime = new Slime(); byte[] utf8 = null; slime.setString(utf8); - assertThat(slime.get().type(), is(Type.NIX)); + assertEquals(Type.NIX, slime.get().type()); verifyEncoding(slime, "null"); } @@ -125,7 +122,7 @@ public class JsonFormatTestCase { public void testNullDataNixFallback() { Slime slime = new Slime(); slime.setData(null); - assertThat(slime.get().type(), is(Type.NIX)); + assertEquals(Type.NIX, slime.get().type()); verifyEncoding(slime, "null"); } @@ -203,7 +200,7 @@ public class JsonFormatTestCase { Slime slime = new Slime(); new JsonDecoder().decode(slime, Utf8.toBytesStd(json)); Cursor a = slime.get().field("body"); - assertThat(a.asString(), is("some text&more text")); + assertEquals("some text&more text", a.asString()); } @Test @@ -226,11 +223,11 @@ public class JsonFormatTestCase { Slime slime = new Slime(); slime = new JsonDecoder().decode(slime, Utf8.toBytesStd(json)); Cursor a = slime.get().field("rules"); - assertThat(a.asString(), is(str)); + assertEquals(str, a.asString()); } @Test(expected = UnsupportedOperationException.class) - public void testThatDecodeIsNotImplemented() throws IOException { + public void testThatDecodeIsNotImplemented() { new JsonFormat(true).decode(null, null); } @@ -244,7 +241,7 @@ public class JsonFormatTestCase { slime.setString("M\u00E6L"); ByteArrayOutputStream a = new ByteArrayOutputStream(); new JsonFormat(true).encode(a, slime); - String val = new String(a.toByteArray(), "UTF-8"); + String val = a.toString(StandardCharsets.UTF_8); assertEquals("\"M\u00E6L\"", val); } @@ -252,7 +249,7 @@ public class JsonFormatTestCase { try { ByteArrayOutputStream a = new ByteArrayOutputStream(); new JsonFormat(compact).encode(a, slime); - assertEquals(expected, new String(a.toByteArray(), StandardCharsets.UTF_8)); + assertEquals(expected, a.toString(StandardCharsets.UTF_8)); } catch (Exception e) { fail("Exception thrown when encoding slime: " + e.getMessage()); } @@ -276,7 +273,7 @@ public class JsonFormatTestCase { slime.setDouble(value); ByteArrayOutputStream a = new ByteArrayOutputStream(); new JsonFormat(true).encode(a, slime); - return new String(a.toByteArray(), StandardCharsets.UTF_8); + return a.toString(StandardCharsets.UTF_8); } catch (Exception e) { return ""; } diff --git a/vespajlib/src/test/java/com/yahoo/slime/SlimeTestCase.java b/vespajlib/src/test/java/com/yahoo/slime/SlimeTestCase.java index 33abfe39345..6ee8fb6c7e2 100644 --- a/vespajlib/src/test/java/com/yahoo/slime/SlimeTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/slime/SlimeTestCase.java @@ -3,8 +3,9 @@ package com.yahoo.slime; import org.junit.Test; -import static org.junit.Assert.assertThat; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.sameInstance; public class SlimeTestCase { diff --git a/vespajlib/src/test/java/com/yahoo/stream/CustomCollectorsTest.java b/vespajlib/src/test/java/com/yahoo/stream/CustomCollectorsTest.java index 6a0e6366775..a5b2accec48 100644 --- a/vespajlib/src/test/java/com/yahoo/stream/CustomCollectorsTest.java +++ b/vespajlib/src/test/java/com/yahoo/stream/CustomCollectorsTest.java @@ -3,9 +3,7 @@ package com.yahoo.stream; import com.google.common.collect.Lists; import com.yahoo.stream.CustomCollectors.DuplicateKeyException; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import java.util.HashMap; import java.util.List; @@ -16,15 +14,13 @@ import static com.yahoo.stream.CustomCollectors.toCustomMap; import static com.yahoo.stream.CustomCollectors.toLinkedMap; import static java.util.function.Function.identity; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; /** * @author gjoranv */ public class CustomCollectorsTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void linked_map_collector_returns_map_with_insertion_order() { List<String> stringList = numberList(); @@ -48,8 +44,12 @@ public class CustomCollectorsTest { public void custom_map_collector_throws_exception_upon_duplicate_keys() { List<String> duplicates = Lists.newArrayList("same", "same"); - thrown.expect(DuplicateKeyException.class); - duplicates.stream().collect(toCustomMap(Function.identity(), Function.identity(), HashMap::new)); + try { + duplicates.stream().collect(toCustomMap(Function.identity(), Function.identity(), HashMap::new)); + fail(); + } catch (DuplicateKeyException e) { + + } } private static List<String> numberList() { diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorTypeTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorTypeTestCase.java index c5009fa3ab2..738697d4521 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorTypeTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorTypeTestCase.java @@ -3,10 +3,8 @@ package com.yahoo.tensor; import org.junit.Test; -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; @@ -117,7 +115,7 @@ public class TensorTypeTestCase { TensorType.fromSpec(typeSpec); fail("Expected exception to be thrown with message: '" + messageSubstring + "'"); } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), containsString(messageSubstring)); + assertTrue(e.getMessage().contains(messageSubstring)); } } diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TypeResolverTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TypeResolverTestCase.java index 055603c5f59..82b7e73fb20 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TypeResolverTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TypeResolverTestCase.java @@ -9,10 +9,7 @@ import java.util.List; import org.junit.Test; 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; /** * @author arnej diff --git a/vespajlib/src/test/java/com/yahoo/text/LowercaseTestCase.java b/vespajlib/src/test/java/com/yahoo/text/LowercaseTestCase.java index 70374adbb16..ca3b316c11b 100644 --- a/vespajlib/src/test/java/com/yahoo/text/LowercaseTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/text/LowercaseTestCase.java @@ -6,9 +6,7 @@ import org.junit.Test; import java.util.Locale; -import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; /** * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> @@ -20,32 +18,32 @@ public class LowercaseTestCase { public void testAZ() { { String lowercase = Lowercase.toLowerCase("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - assertThat(lowercase, equalTo("abcdefghijklmnopqrstuvwxyz")); + assertEquals("abcdefghijklmnopqrstuvwxyz", lowercase); } { String lowercase = Lowercase.toLowerCase("abcdefghijklmnopqrstuvwxyz"); - assertThat(lowercase, equalTo("abcdefghijklmnopqrstuvwxyz")); + assertEquals("abcdefghijklmnopqrstuvwxyz", lowercase); } { String lowercase = Lowercase.toLowerCase("AbCDEfGHIJklmnoPQRStuvwXyz"); - assertThat(lowercase, equalTo("abcdefghijklmnopqrstuvwxyz")); + assertEquals("abcdefghijklmnopqrstuvwxyz", lowercase); } { String lowercase = Lowercase.toLowerCase("@+#"); - assertThat(lowercase, equalTo("@+#")); + assertEquals("@+#", lowercase); } { String lowercase = Lowercase.toLowerCase("[]"); - assertThat(lowercase, equalTo("[]")); + assertEquals("[]", lowercase); } { String lowercase = Lowercase.toLowerCase("{}"); - assertThat(lowercase, equalTo("{}")); + assertEquals("{}", lowercase); } { String lowercase = Lowercase.toLowerCase("\u00cd\u00f4"); - assertThat(lowercase, equalTo("\u00ed\u00f4")); + assertEquals("\u00ed\u00f4", lowercase); } } diff --git a/vespajlib/src/test/java/com/yahoo/text/StringUtilitiesTest.java b/vespajlib/src/test/java/com/yahoo/text/StringUtilitiesTest.java index b1ec37cb7d7..b68cca6e54f 100644 --- a/vespajlib/src/test/java/com/yahoo/text/StringUtilitiesTest.java +++ b/vespajlib/src/test/java/com/yahoo/text/StringUtilitiesTest.java @@ -1,12 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.text; -import java.util.Arrays; +import java.util.List; import org.junit.Test; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; public class StringUtilitiesTest { @@ -40,7 +43,7 @@ public class StringUtilitiesTest { @Test public void testImplode() { - assertEquals(StringUtilities.implode(null, null), null); + assertNull(StringUtilities.implode(null, null)); assertEquals(StringUtilities.implode(new String[0], null), ""); assertEquals(StringUtilities.implode(new String[] {"foo"}, null), "foo"); assertEquals(StringUtilities.implode(new String[] {"foo"}, "asdfsdfsadfsadfasdfs"), "foo"); @@ -55,17 +58,17 @@ public class StringUtilitiesTest { @Test public void testImplodeMultiline() { - assertEquals(StringUtilities.implodeMultiline(Arrays.asList("foo", "bar")), "foo\nbar"); - assertEquals(StringUtilities.implodeMultiline(Arrays.asList("")), ""); - assertEquals(StringUtilities.implodeMultiline(null), null); - assertEquals(StringUtilities.implodeMultiline(Arrays.asList("\n")), "\n"); + assertEquals(StringUtilities.implodeMultiline(List.of("foo", "bar")), "foo\nbar"); + assertEquals(StringUtilities.implodeMultiline(List.of("")), ""); + assertNull(StringUtilities.implodeMultiline(null)); + assertEquals(StringUtilities.implodeMultiline(List.of("\n")), "\n"); } @Test public void testTruncation() { String a = "abbc"; - assertTrue(a == StringUtilities.truncateSequencesIfNecessary(a, 2)); - assertTrue(a != StringUtilities.truncateSequencesIfNecessary(a, 1)); + assertSame(a, StringUtilities.truncateSequencesIfNecessary(a, 2)); + assertNotSame(a, StringUtilities.truncateSequencesIfNecessary(a, 1)); assertEquals("abc", StringUtilities.truncateSequencesIfNecessary(a, 1)); assertEquals("abc", StringUtilities.truncateSequencesIfNecessary("aabbccc", 1)); assertEquals("abc", StringUtilities.truncateSequencesIfNecessary("abcc", 1)); @@ -77,9 +80,9 @@ public class StringUtilitiesTest { @Test public void testStripSuffix() { - assertThat(StringUtilities.stripSuffix("abc.def", ".def"), is("abc")); - assertThat(StringUtilities.stripSuffix("abc.def", ""), is("abc.def")); - assertThat(StringUtilities.stripSuffix("", ".def"), is("")); - assertThat(StringUtilities.stripSuffix("", ""), is("")); + assertEquals("abc", StringUtilities.stripSuffix("abc.def", ".def")); + assertEquals("abc.def", StringUtilities.stripSuffix("abc.def", "")); + assertTrue(StringUtilities.stripSuffix("", ".def").isEmpty()); + assertTrue(StringUtilities.stripSuffix("", "").isEmpty()); } } diff --git a/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java b/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java index 9e43cb3c6ea..926d19f433f 100644 --- a/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java +++ b/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java @@ -18,9 +18,9 @@ import static com.yahoo.text.Utf8.calculateBytePositions; import static com.yahoo.text.Utf8.calculateStringPositions; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** diff --git a/vespajlib/src/test/java/com/yahoo/vespa/objects/FieldBaseTestCase.java b/vespajlib/src/test/java/com/yahoo/vespa/objects/FieldBaseTestCase.java index 40792ac05c1..32b87a4b373 100644 --- a/vespajlib/src/test/java/com/yahoo/vespa/objects/FieldBaseTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/vespa/objects/FieldBaseTestCase.java @@ -6,9 +6,7 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author arnej27959 diff --git a/vespajlib/src/test/java/com/yahoo/vespa/objects/ObjectDumperTestCase.java b/vespajlib/src/test/java/com/yahoo/vespa/objects/ObjectDumperTestCase.java index 7694548344c..ab0da1b7d33 100644 --- a/vespajlib/src/test/java/com/yahoo/vespa/objects/ObjectDumperTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/vespa/objects/ObjectDumperTestCase.java @@ -3,13 +3,9 @@ package com.yahoo.vespa.objects; import org.junit.Test; -import java.nio.ByteBuffer; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; /** * @author arnej27959 @@ -37,7 +33,7 @@ public class ObjectDumperTestCase { oneOD.visit("biggie", b); - assertThat(oneOD.toString(), equalTo( + assertEquals( "biggie: BigIdClass {\n"+ " classId: 42\n"+ " : <NULL>\n"+ @@ -69,11 +65,11 @@ public class ObjectDumperTestCase { " [3]: 4\n"+ " [4]: 5\n"+ " }\n"+ -"}\n")); +"}\n", oneOD.toString()); ObjectDumper defOD = new ObjectDumper(); defOD.visit("", b); - assertThat(b.toString(), equalTo(b.toString())); + assertEquals(b.toString(), b.toString()); } @Test @@ -100,7 +96,7 @@ public class ObjectDumperTestCase { defOD.visit("s5", s5); oneOD.visit("s6", s5); - assertThat(defOD.toString(), is("s5: FooBarIdClass {\n"+ + assertEquals("s5: FooBarIdClass {\n"+ " classId: 17\n"+ " foo: 'def-foo'\n"+ " bar: 42\n"+ @@ -109,8 +105,8 @@ public class ObjectDumperTestCase { " [1]: 42\n"+ " [2]: 666\n"+ " }\n"+ - "}\n")); - assertThat(oneOD.toString(), is("s6: FooBarIdClass {\n"+ + "}\n", defOD.toString()); + assertEquals("s6: FooBarIdClass {\n"+ " classId: 17\n"+ " foo: 'def-foo'\n"+ " bar: 42\n"+ @@ -119,31 +115,29 @@ public class ObjectDumperTestCase { " [1]: 42\n"+ " [2]: 666\n"+ " }\n"+ - "}\n")); + "}\n", oneOD.toString()); } @Test public void testRegistry() { - assertThat(FooBarIdClass.classId, is(17)); + assertEquals(17, FooBarIdClass.classId); int x = Identifiable.registerClass(17, FooBarIdClass.class); - assertThat(x, is(17)); - boolean caught = false; + assertEquals(17, x); try { - x = Identifiable.registerClass(17, SomeIdClass.class); + x = Identifiable.registerClass(17, SomeIdClass.class); + fail(); } catch (IllegalArgumentException e) { - caught = true; - assertThat(e.getMessage(), is( + assertEquals(e.getMessage(), "Can not register class 'class com.yahoo.vespa.objects.SomeIdClass' with id 17,"+ -" because it already maps to class 'class com.yahoo.vespa.objects.FooBarIdClass'.")); +" because it already maps to class 'class com.yahoo.vespa.objects.FooBarIdClass'."); } - assertThat(x, is(17)); - assertThat(caught, is(true)); + assertEquals(17, x); Identifiable s7 = Identifiable.createFromId(17); ObjectDumper defOD = new ObjectDumper(); defOD.visit("s7", s7); - assertThat(defOD.toString(), is("s7: FooBarIdClass {\n"+ + assertEquals("s7: FooBarIdClass {\n"+ " classId: 17\n"+ " foo: 'def-foo'\n"+ " bar: 42\n"+ @@ -152,10 +146,9 @@ public class ObjectDumperTestCase { " [1]: 42\n"+ " [2]: 666\n"+ " }\n"+ - "}\n")); + "}\n", defOD.toString()); - Identifiable nsi = Identifiable.createFromId(717273); - assertThat(nsi, is((Identifiable)null)); + assertNull(Identifiable.createFromId(717273)); } } diff --git a/vespajlib/src/test/java/com/yahoo/vespa/objects/SerializeTestCase.java b/vespajlib/src/test/java/com/yahoo/vespa/objects/SerializeTestCase.java index ce4f6846248..31c43f6008d 100644 --- a/vespajlib/src/test/java/com/yahoo/vespa/objects/SerializeTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/vespa/objects/SerializeTestCase.java @@ -8,7 +8,7 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author arnej27959 |