diff --git a/bundles/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/history/RefactoringHistoryManager.java b/bundles/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/history/RefactoringHistoryManager.java index a0853fac3d3..357fb511958 100644 --- a/bundles/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/history/RefactoringHistoryManager.java +++ b/bundles/org.eclipse.ltk.core.refactoring/src/org/eclipse/ltk/internal/core/refactoring/history/RefactoringHistoryManager.java @@ -23,7 +23,7 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -709,7 +709,7 @@ public static void writeRefactoringSession(final OutputStream stream, final Refa } private static void writeNode(final OutputStream stream, Document document) { - try (DOMWriter writer= new DOMWriter(new OutputStreamWriter(stream, Charset.forName("UTF-8")))){ //$NON-NLS-1$ + try (DOMWriter writer= new DOMWriter(new OutputStreamWriter(stream, StandardCharsets.UTF_8))) { writer.printDocument(document); writer.flush(); } diff --git a/tests/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/history/RefactoringHistorySerializationTests.java b/tests/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/history/RefactoringHistorySerializationTests.java index d48ba2fecd6..62181b4dd0d 100644 --- a/tests/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/history/RefactoringHistorySerializationTests.java +++ b/tests/org.eclipse.ltk.core.refactoring.tests/src/org/eclipse/ltk/core/refactoring/tests/history/RefactoringHistorySerializationTests.java @@ -15,12 +15,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -49,42 +48,34 @@ private static void compareReadHistory(RefactoringDescriptor[] descriptors, int for (RefactoringDescriptor descriptor : descriptors) { list.add(new RefactoringDescriptorProxyAdapter(descriptor)); } - try { - ByteArrayInputStream stream= null; - if (ioException) { - stream= new ByteArrayInputStream(xml.getBytes("utf-8")) { - - @Override - public int read(byte[] b) throws IOException { - throw new IOException(); - } - }; - } else - stream= new ByteArrayInputStream(xml.getBytes("utf-8")); - RefactoringHistory result= RefactoringCore.getHistoryService().readRefactoringHistory(stream, flags); - RefactoringDescriptorProxy[] actualProxies= result.getDescriptors(); - RefactoringDescriptorProxy[] expectedProxies= list.toArray(new RefactoringDescriptorProxy[list.size()]); - assertEquals("The number of refactoring descriptors is incorrect.", expectedProxies.length, actualProxies.length); - for (int index= 0; index < expectedProxies.length; index++) { - RefactoringDescriptor expectedDescriptor= expectedProxies[index].requestDescriptor(null); - assertNotNull("Expected refactoring descriptor cannot be resolved.", expectedDescriptor); - RefactoringDescriptor actualDescriptor= actualProxies[index].requestDescriptor(null); - assertNotNull("Actual refactoring descriptor cannot be resolved.", actualDescriptor); - assertEquals("Expected refactoring descriptor is not equal to actual one:", expectedDescriptor.toString(), actualDescriptor.toString()); - } - } catch (UnsupportedEncodingException exception) { - fail("Unsupported encoding for ByteArrayOutputStream."); + ByteArrayInputStream stream= null; + if (ioException) { + stream= new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)) { + + @Override + public int read(byte[] b) throws IOException { + throw new IOException(); + } + }; + } else + stream= new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); + RefactoringHistory result= RefactoringCore.getHistoryService().readRefactoringHistory(stream, flags); + RefactoringDescriptorProxy[] actualProxies= result.getDescriptors(); + RefactoringDescriptorProxy[] expectedProxies= list.toArray(new RefactoringDescriptorProxy[list.size()]); + assertEquals("The number of refactoring descriptors is incorrect.", expectedProxies.length, actualProxies.length); + for (int index= 0; index < expectedProxies.length; index++) { + RefactoringDescriptor expectedDescriptor= expectedProxies[index].requestDescriptor(null); + assertNotNull("Expected refactoring descriptor cannot be resolved.", expectedDescriptor); + RefactoringDescriptor actualDescriptor= actualProxies[index].requestDescriptor(null); + assertNotNull("Actual refactoring descriptor cannot be resolved.", actualDescriptor); + assertEquals("Expected refactoring descriptor is not equal to actual one:", expectedDescriptor.toString(), actualDescriptor.toString()); } } private static void compareWrittenDescriptor(RefactoringSessionDescriptor descriptor, boolean time, String xml) throws CoreException { ByteArrayOutputStream stream= new ByteArrayOutputStream(); RefactoringCore.getHistoryService().writeRefactoringSession(descriptor, stream, time); - try { - assertEquals("The refactoring descriptor has not been correctly serialized:", convertLineDelimiters(xml), stream.toString("utf-8")); - } catch (UnsupportedEncodingException exception) { - fail("Unsupported encoding for ByteArrayOutputStream."); - } + assertEquals("The refactoring descriptor has not been correctly serialized:", convertLineDelimiters(xml), stream.toString(StandardCharsets.UTF_8)); } private static String concatenate(String[] lines, String delimiter) {