From 3f96fe4e1a96b3b21c913a392da87e5ec669b286 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 5 Oct 2020 15:04:38 +0200 Subject: Revert "Remove unused Utf8 methods" --- .../test/java/com/yahoo/io/ByteWriterTestCase.java | 22 +++++++++++----------- .../test/java/com/yahoo/io/FileReadTestCase.java | 10 +++++----- .../test/java/com/yahoo/io/HexDumpTestCase.java | 19 ++++++++++++++----- .../java/com/yahoo/io/SlowInflateTestCase.java | 16 ++++++++-------- .../java/com/yahoo/slime/JsonFormatTestCase.java | 9 +++++---- .../src/test/java/com/yahoo/text/Utf8TestCase.java | 8 ++++---- 6 files changed, 47 insertions(+), 37 deletions(-) (limited to 'vespajlib/src/test/java/com') diff --git a/vespajlib/src/test/java/com/yahoo/io/ByteWriterTestCase.java b/vespajlib/src/test/java/com/yahoo/io/ByteWriterTestCase.java index 77967bb08fa..c6278133d4c 100644 --- a/vespajlib/src/test/java/com/yahoo/io/ByteWriterTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/ByteWriterTestCase.java @@ -1,23 +1,23 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.io; -import com.yahoo.text.Utf8; -import com.yahoo.text.Utf8Array; -import org.junit.Test; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.IdentityHashMap; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import com.yahoo.text.Utf8; +import com.yahoo.text.Utf8Array; +import org.junit.Test; /** * Test the ByteWriter class. ByteWriter is also implicitly tested in @@ -27,7 +27,7 @@ import static org.junit.Assert.fail; */ public class ByteWriterTestCase { - private final CharsetEncoder encoder = StandardCharsets.UTF_8.newEncoder(); + private final CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder(); private final ByteArrayOutputStream stream = new ByteArrayOutputStream(); /** @@ -281,7 +281,7 @@ public class ByteWriterTestCase { @Test public void testUnMappableCharacter() throws java.io.IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); - ByteWriter writer = new ByteWriter(stream, StandardCharsets.US_ASCII.newEncoder()); + ByteWriter writer = new ByteWriter(stream, Charset.forName("ascii").newEncoder()); writer.write("yahoo\u9999bahoo"); writer.close(); assertTrue(stream.toString("ascii").contains("yahoo")); diff --git a/vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java b/vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java index 4769562db89..1acd225b18a 100644 --- a/vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java @@ -1,4 +1,4 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.io; import org.junit.Test; @@ -6,7 +6,7 @@ import org.junit.Test; import java.io.File; import java.io.IOException; import java.io.StringReader; -import java.nio.charset.StandardCharsets; +import java.nio.charset.Charset; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -16,15 +16,15 @@ public class FileReadTestCase { @Test public void testReadByteArray() throws IOException { byte[] thisFile = IOUtils.readFileBytes(new File("src/test/java/com/yahoo/io/FileReadTestCase.java")); - String str = new String(thisFile, StandardCharsets.US_ASCII); - assertTrue(str.startsWith("// Copyright Verizon Media.")); + String str = new String(thisFile, Charset.forName("US-ASCII")); + assertTrue(str.startsWith("// Copyright 2017 Yahoo Holdings.")); assertTrue(str.endsWith("// Yeppers\n")); } @Test public void testReadString() throws IOException { String str = IOUtils.readFile(new File("src/test/java/com/yahoo/io/FileReadTestCase.java")); - assertTrue(str.startsWith("// Copyright Verizon Media.")); + assertTrue(str.startsWith("// Copyright 2017 Yahoo Holdings.")); assertTrue(str.endsWith("// Yeppers\n")); } diff --git a/vespajlib/src/test/java/com/yahoo/io/HexDumpTestCase.java b/vespajlib/src/test/java/com/yahoo/io/HexDumpTestCase.java index d250338b8fe..dcea8101d9c 100644 --- a/vespajlib/src/test/java/com/yahoo/io/HexDumpTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/HexDumpTestCase.java @@ -1,19 +1,28 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.io; import org.junit.Test; -import java.nio.charset.StandardCharsets; +import com.yahoo.text.Utf8; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; /** * @author Simon Thoresen Hult - * @author Steinar Knutsen + * @author Steinar Knutsen */ public class HexDumpTestCase { + private static final Charset UTF8 = Charset.forName("UTF-8"); + private static final Charset UTF16 = Charset.forName("UTF-16"); + @Test public void requireThatToHexStringAcceptsNull() { assertNull(HexDump.toHexString(null)); @@ -22,10 +31,10 @@ public class HexDumpTestCase { @Test public void requireThatToHexStringIsUnformatted() { assertEquals("6162636465666768696A6B6C6D6E6F707172737475767778797A", - HexDump.toHexString("abcdefghijklmnopqrstuvwxyz".getBytes(StandardCharsets.UTF_8))); + HexDump.toHexString("abcdefghijklmnopqrstuvwxyz".getBytes(UTF8))); assertEquals("FEFF006100620063006400650066006700680069006A006B006C00" + "6D006E006F0070007100720073007400750076007700780079007A", - HexDump.toHexString("abcdefghijklmnopqrstuvwxyz".getBytes(StandardCharsets.UTF_16))); + HexDump.toHexString("abcdefghijklmnopqrstuvwxyz".getBytes(UTF16))); } } diff --git a/vespajlib/src/test/java/com/yahoo/io/SlowInflateTestCase.java b/vespajlib/src/test/java/com/yahoo/io/SlowInflateTestCase.java index 7f374441a18..7726cd7ea68 100644 --- a/vespajlib/src/test/java/com/yahoo/io/SlowInflateTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/SlowInflateTestCase.java @@ -1,20 +1,20 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.io; -import org.junit.Before; -import org.junit.Test; +import static org.junit.Assert.*; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.zip.Deflater; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; + +import com.yahoo.text.Utf8; /** * Check decompressor used among other things for packed summary fields. * - * @author Steinar Knutsen + * @author Steinar Knutsen */ public class SlowInflateTestCase { @@ -27,7 +27,7 @@ public class SlowInflateTestCase { @Before public void setUp() throws Exception { value = "000000000000000000000000000000000000000000000000000000000000000"; - raw = value.getBytes(StandardCharsets.UTF_8); + raw = Utf8.toBytesStd(value); output = new byte[raw.length * 2]; Deflater compresser = new Deflater(); compresser.setInput(raw); diff --git a/vespajlib/src/test/java/com/yahoo/slime/JsonFormatTestCase.java b/vespajlib/src/test/java/com/yahoo/slime/JsonFormatTestCase.java index 3b31c2b559e..44aa4ab2ff7 100644 --- a/vespajlib/src/test/java/com/yahoo/slime/JsonFormatTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/slime/JsonFormatTestCase.java @@ -1,7 +1,8 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.slime; import com.yahoo.text.Utf8; +import org.junit.Ignore; import org.junit.Test; import java.io.ByteArrayOutputStream; @@ -200,7 +201,7 @@ public class JsonFormatTestCase { public void testDecodeUnicodeAmp() { final String json = "{\"body\":\"some text\\u0026more text\"}"; Slime slime = new Slime(); - new JsonDecoder().decode(slime, json.getBytes(StandardCharsets.UTF_8)); + new JsonDecoder().decode(slime, Utf8.toBytesStd(json)); Cursor a = slime.get().field("body"); assertThat(a.asString(), is("some text&more text")); } @@ -223,7 +224,7 @@ public class JsonFormatTestCase { " }\n"; Slime slime = new Slime(); - slime = new JsonDecoder().decode(slime, json.getBytes(StandardCharsets.UTF_8)); + slime = new JsonDecoder().decode(slime, Utf8.toBytesStd(json)); Cursor a = slime.get().field("rules"); assertThat(a.asString(), is(str)); } @@ -260,7 +261,7 @@ public class JsonFormatTestCase { private void verifyEncodeDecode(String json, boolean compact) { try { Slime slime = new Slime(); - new JsonDecoder().decode(slime, json.getBytes(StandardCharsets.UTF_8)); + new JsonDecoder().decode(slime, Utf8.toBytesStd(json)); ByteArrayOutputStream a = new ByteArrayOutputStream(); new JsonFormat(compact).encode(a, slime); assertEquals(json, Utf8.toString(a.toByteArray())); diff --git a/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java b/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java index 8293554140d..97d0717dc0b 100644 --- a/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java +++ b/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java @@ -1,4 +1,4 @@ -// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.text; import com.google.common.collect.ImmutableMap; @@ -24,8 +24,8 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** - * @author Bjorn Borud - * @author Steinar Knutsen + * @author Bjorn Borud + * @author Steinar Knutsen */ public class Utf8TestCase { @@ -322,7 +322,7 @@ public class Utf8TestCase { for (char c=0; c < i; c++) { sb.append(c); } - assertTrue(Arrays.equals(sb.toString().getBytes(StandardCharsets.UTF_8), Utf8.toBytes(sb.toString()))); + assertTrue(Arrays.equals(Utf8.toBytesStd(sb.toString()), Utf8.toBytes(sb.toString()))); } } -- cgit v1.2.3