Improve test coverage with test on error message for nested heterogenous

arrays
This commit is contained in:
moandji.ezana 2015-07-01 12:59:12 +02:00
parent 1244fdbfb3
commit fa591a0f0c

View file

@ -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);
}