diff --git a/core/src/main/java/google/registry/tools/GetTldCommand.java b/core/src/main/java/google/registry/tools/GetTldCommand.java index 5bef26b30..b68dafef0 100644 --- a/core/src/main/java/google/registry/tools/GetTldCommand.java +++ b/core/src/main/java/google/registry/tools/GetTldCommand.java @@ -16,12 +16,15 @@ package google.registry.tools; import static google.registry.model.tld.TldYamlUtils.getObjectMapper; import static google.registry.model.tld.Tlds.assertTldsExist; +import static java.nio.charset.StandardCharsets.UTF_8; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import google.registry.model.tld.Tld; +import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.util.List; /** Command to show a TLD record. */ @@ -34,10 +37,12 @@ final class GetTldCommand implements Command { private List mainParameters; @Override - public void run() throws JsonProcessingException { + public void run() throws JsonProcessingException, UnsupportedEncodingException { ObjectMapper mapper = getObjectMapper(); - for (String tld : assertTldsExist(mainParameters)) { - System.out.println(mapper.writeValueAsString(Tld.get(tld))); + try (PrintStream printStream = new PrintStream(System.out, false, UTF_8.name())) { + for (String tld : assertTldsExist(mainParameters)) { + printStream.println(mapper.writeValueAsString(Tld.get(tld))); + } } } } diff --git a/core/src/test/java/google/registry/tools/CommandTestCase.java b/core/src/test/java/google/registry/tools/CommandTestCase.java index a37dd0778..dfc257ccc 100644 --- a/core/src/test/java/google/registry/tools/CommandTestCase.java +++ b/core/src/test/java/google/registry/tools/CommandTestCase.java @@ -80,11 +80,12 @@ public abstract class CommandTestCase { RegistryToolEnvironment.UNITTEST.setup(systemPropertyExtension); command = newCommandInstance(); - // Capture standard output/error. + // Capture standard output/error. Use a single-byte encoding to emulate platforms where default + // charset is not UTF_8. oldStdout = System.out; - System.setOut(new PrintStream(new OutputSplitter(System.out, stdout))); + System.setOut(new PrintStream(new OutputSplitter(System.out, stdout), false, "US-ASCII")); oldStderr = System.err; - System.setErr(new PrintStream(new OutputSplitter(System.err, stderr))); + System.setErr(new PrintStream(new OutputSplitter(System.err, stderr), false, "US-ASCII")); } @AfterEach diff --git a/core/src/test/java/google/registry/tools/GetTldCommandTest.java b/core/src/test/java/google/registry/tools/GetTldCommandTest.java index 5dfb6f61b..5ce11fd27 100644 --- a/core/src/test/java/google/registry/tools/GetTldCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetTldCommandTest.java @@ -20,14 +20,11 @@ import static google.registry.testing.TestDataHelper.loadFile; import static org.junit.jupiter.api.Assertions.assertThrows; import com.beust.jcommander.ParameterException; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** Unit tests for {@link GetTldCommand}. */ class GetTldCommandTest extends CommandTestCase { - // TODO (sarahbot): re-enable this test after we figure out why it fails during RC build. - @Disabled @Test void testSuccess() throws Exception { createTld("xn--q9jyb4c");