Fix build
This commit is contained in:
@ -11,6 +11,7 @@ import java.util.Locale;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
|
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
|
||||||
@ -115,19 +116,22 @@ public class PMDTaskTest extends AbstractAntTestHelper {
|
|||||||
System.setProperty("file.encoding", charsetName);
|
System.setProperty("file.encoding", charsetName);
|
||||||
Field charset = Charset.class.getDeclaredField("defaultCharset");
|
Field charset = Charset.class.getDeclaredField("defaultCharset");
|
||||||
charset.setAccessible(true);
|
charset.setAccessible(true);
|
||||||
charset.set(null,null);
|
charset.set(null, null);
|
||||||
Objects.requireNonNull(Charset.defaultCharset());
|
Objects.requireNonNull(Charset.defaultCharset());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final TestRule restoreDefaultCharset = new ExternalResource() {
|
public final TestRule restoreDefaultCharset = new ExternalResource() {
|
||||||
private Charset defaultCharset;
|
private Charset defaultCharset;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void before() throws Throwable {
|
protected void before() throws Throwable {
|
||||||
defaultCharset = Charset.defaultCharset();
|
defaultCharset = Charset.defaultCharset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void after() {
|
protected void after() {
|
||||||
setDefaultCharset(defaultCharset.name());
|
setDefaultCharset(defaultCharset.name());
|
||||||
@ -141,7 +145,7 @@ public class PMDTaskTest extends AbstractAntTestHelper {
|
|||||||
|
|
||||||
executeTarget("testFormatterEncodingWithXML");
|
executeTarget("testFormatterEncodingWithXML");
|
||||||
String report = FileUtils.readFileToString(new File("target/testFormatterEncodingWithXML-pmd.xml"), "UTF-8");
|
String report = FileUtils.readFileToString(new File("target/testFormatterEncodingWithXML-pmd.xml"), "UTF-8");
|
||||||
assertTrue(report.contains("unusedVariableWithÜmlaut"));
|
Assert.assertTrue(report.contains("unusedVariableWithÜmlaut"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -149,8 +153,8 @@ public class PMDTaskTest extends AbstractAntTestHelper {
|
|||||||
setDefaultCharset("cp1252");
|
setDefaultCharset("cp1252");
|
||||||
|
|
||||||
executeTarget("testFormatterEncodingWithXMLConsole");
|
executeTarget("testFormatterEncodingWithXMLConsole");
|
||||||
String report = getOutput();
|
String report = buildRule.getOutput();
|
||||||
assertTrue(report.startsWith("<?xml version=\"1.0\" encoding=\"windows-1252\"?>"));
|
Assert.assertTrue(report.startsWith("<?xml version=\"1.0\" encoding=\"windows-1252\"?>"));
|
||||||
assertTrue(report.contains("unusedVariableWithÜmlaut"));
|
Assert.assertTrue(report.contains("unusedVariableWithÜmlaut"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user