Beispiel #1
0
 @Test
 public void testStringDict() throws Exception {
   Object input =
       ImmutableMap.of(
           "foo", "bar",
           "wiz", "bang");
   Map<String, String> converted = Type.STRING_DICT.convert(input, null);
   assertEquals(input, converted);
   assertNotSame(input, converted);
   assertThat(Type.STRING_DICT.flatten(converted)).isEmpty();
 }
Beispiel #2
0
 @Test
 public void testStringDictThrowsConversionException() throws Exception {
   try {
     Type.STRING_DICT.convert("some string", null);
     fail();
   } catch (ConversionException e) {
     assertThat(e).hasMessage("Expected a map for dictionary but got a java.lang.String");
   }
 }
Beispiel #3
0
 @Test
 public void testStringDictBadElements() throws Exception {
   Object input = ImmutableMap.of("foo", Arrays.asList("bar", "baz"), "wiz", "bang");
   try {
     Type.STRING_DICT.convert(input, null);
     fail();
   } catch (Type.ConversionException e) {
     assertThat(e)
         .hasMessage(
             "expected value of type 'string' for dict value element, "
                 + "but got [\"bar\", \"baz\"] (List)");
   }
 }