Skip to content

Commit

Permalink
ConfigurationEncodingTests.testGetSystemDefaultEncoding failure (#77)
Browse files Browse the repository at this point in the history
Updated test to use Platform.getSystemCharset() API.

Note: running this test in the IDE still fails because IDE ALWAYS sets
"file.encoding" system property, see
#24

Fixes #77
  • Loading branch information
iloveeclipse committed Jun 23, 2022
1 parent e7b9488 commit cc699b9
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
Expand Down Expand Up @@ -60,21 +61,20 @@ protected String getDefaultEncoding() {
*/
public void testGetSystemDefaultEncoding() throws CoreException {
String oldencoding = ResourcesPlugin.getEncoding();
String oldsystemencoding = System.getProperty("file.encoding");
String defaultEncoding = getDefaultEncoding();
String systemEncoding = Platform.getSystemCharset().name();
try {
getResourcesPreferences().setValue(ResourcesPlugin.PREF_ENCODING, getDefaultEncoding());
System.setProperty("file.encoding", "UTF-16BE");
getResourcesPreferences().setValue(ResourcesPlugin.PREF_ENCODING, defaultEncoding);
ILaunchConfiguration config = getLaunchConfiguration("LaunchHistoryTest");
assertNotNull("the configuration could not be found", config);
assertTrue("there should be no encoding set on the configuration", config.getAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, (String) null) == null);
String encoding = getLaunchManager().getEncoding(config);
assertNotNull("The configuration encoding should not be null", encoding);
assertEquals("The configuration encoding should match the file system encoding", encoding, System.getProperty("file.encoding"));
assertEquals("The configuration encoding should match the file system encoding", systemEncoding, encoding);
}
finally {
//ensure old encoding is restored
getResourcesPreferences().setValue(ResourcesPlugin.PREF_ENCODING, (oldencoding == null ? getDefaultEncoding() : oldencoding));
System.setProperty("file.encoding", oldsystemencoding);
getResourcesPreferences().setValue(ResourcesPlugin.PREF_ENCODING, (oldencoding == null ? defaultEncoding : oldencoding));
}
}

Expand Down

0 comments on commit cc699b9

Please sign in to comment.