@@ -27,7 +27,10 @@ import java.util.Arrays;
import java.util.Collection;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(Enclosed.class)
public class CharSetTest {
@@ -37,7 +40,10 @@ public class CharSetTest {
// requires JUnit 4.12
@Parameterized.Parameters(name = "legal argument: |{0}|")
public static Collection<String> data() {
return Arrays.asList("UTF-8", "ISO-8859-1", "037", "us", "IBM500");
return Arrays.asList("UTF-8", "ISO-8859-1", "037", "us", "IBM500",
// some java.io encodings are not provided as aliases in java.nio.charset
// so, for backwards compatibility, the case should not matter
"ascii", "utf-8", "Cp1252");
}
@Parameterized.Parameter
@@ -46,7 +52,7 @@ public class CharSetTest {
@Test
public void testCorrectNames() {
CharSet cs = new CharSet(argument);
assertThat(argument, equalTo(cs.getValue()));
assertThat(argument, equalToIgnoringCase (cs.getValue()));
}
}
@@ -63,7 +69,41 @@ public class CharSetTest {
@Test(expected = BuildException.class)
public void testNonExistentNames() {
new CharSet().setValue(argument);
new CharSet(argument);
}
}
@RunWith(Parameterized.class)
public static class LegalEquivalenceTest {
// requires JUnit 4.12
@Parameterized.Parameters(name = "equivalent argument: |{0}|")
public static Collection<String> data() {
return Arrays.asList("UTF8", "unicode-1-1-utf-8");
}
@Parameterized.Parameter
public String argument;
@Test
public void testCorrectNames() {
assertTrue(new CharSet(argument).equivalent(CharSet.getUtf8()));
}
}
@RunWith(Parameterized.class)
public static class IncorrectEquivalenceTest {
// requires JUnit 4.12
@Parameterized.Parameters(name = "non-equivalent argument: |{0}|")
public static Collection<String> data() {
return Arrays.asList("us", "ISO-8859-1", "default");
}
@Parameterized.Parameter
public String argument;
@Test
public void testIncorrectNames() {
assertFalse(new CharSet(argument).equivalent(CharSet.getUtf8()));
}
}