mirror of
https://github.com/plexusorg/toml4j.git
synced 2024-12-29 11:42:15 +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.TimeZone;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -32,6 +34,9 @@ public class TomlWriterTest {
|
|||
|
||||
@Rule
|
||||
public TemporaryFolder testDirectory = new TemporaryFolder();
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void should_write_primitive_types() {
|
||||
|
@ -222,7 +227,7 @@ public class TomlWriterTest {
|
|||
assertEquals("", new TomlWriter().write(new TestClass()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void should_reject_heterogeneous_arrays() {
|
||||
class BadArray {
|
||||
Object[] array = new Object[2];
|
||||
|
@ -231,6 +236,24 @@ public class TomlWriterTest {
|
|||
badArray.array[0] = new Integer(1);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue