mirror of
https://github.com/plexusorg/toml4j.git
synced 2025-01-03 22:08:46 +00:00
Improve test coverage with test on error message for nested heterogenous
arrays
This commit is contained in:
parent
1244fdbfb3
commit
fa591a0f0c
1 changed files with 24 additions and 1 deletions
|
@ -23,8 +23,10 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
@ -33,6 +35,9 @@ public class TomlWriterTest {
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder testDirectory = new TemporaryFolder();
|
public TemporaryFolder testDirectory = new TemporaryFolder();
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public ExpectedException expectedException = ExpectedException.none();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void should_write_primitive_types() {
|
public void should_write_primitive_types() {
|
||||||
class TestClass {
|
class TestClass {
|
||||||
|
@ -222,7 +227,7 @@ public class TomlWriterTest {
|
||||||
assertEquals("", new TomlWriter().write(new TestClass()));
|
assertEquals("", new TomlWriter().write(new TestClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test
|
||||||
public void should_reject_heterogeneous_arrays() {
|
public void should_reject_heterogeneous_arrays() {
|
||||||
class BadArray {
|
class BadArray {
|
||||||
Object[] array = new Object[2];
|
Object[] array = new Object[2];
|
||||||
|
@ -231,6 +236,24 @@ public class TomlWriterTest {
|
||||||
badArray.array[0] = new Integer(1);
|
badArray.array[0] = new Integer(1);
|
||||||
badArray.array[1] = "oops";
|
badArray.array[1] = "oops";
|
||||||
|
|
||||||
|
expectedException.expect(IllegalStateException.class);
|
||||||
|
expectedException.expectMessage(Matchers.startsWith("array"));
|
||||||
|
|
||||||
|
new TomlWriter().write(badArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void should_reject_nested_heterogeneous_array() {
|
||||||
|
class BadArray {
|
||||||
|
Map<String, Object> aMap = new HashMap<String, Object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
BadArray badArray = new BadArray();
|
||||||
|
badArray.aMap.put("array", new Object[] { Integer.valueOf(1), "oops" });
|
||||||
|
|
||||||
|
expectedException.expect(IllegalStateException.class);
|
||||||
|
expectedException.expectMessage("aMap.array");
|
||||||
|
|
||||||
new TomlWriter().write(badArray);
|
new TomlWriter().write(badArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue