Exemplo n.º 1
0
 @Test
 public void testStringList() throws Exception {
   Object input = Arrays.asList("foo", "bar", "wiz");
   List<String> converted = Type.STRING_LIST.convert(input, null);
   assertEquals(input, converted);
   assertNotSame(input, converted);
   assertThat(Type.STRING_LIST.flatten(input)).isEmpty();
 }
Exemplo n.º 2
0
 @Test
 public void testNonStringList() throws Exception {
   try {
     Type.STRING_LIST.convert(3, "blah");
     fail();
   } catch (Type.ConversionException e) {
     assertThat(e).hasMessage("expected value of type 'list(string)' for blah, but got 3 (int)");
   }
 }
Exemplo n.º 3
0
 // Ensure that types are reported correctly.
 @Test
 public void testTypeErrorMessage() throws Exception {
   try {
     Type.STRING_LIST.convert("[(1,2), 3, 4]", "myexpr", null);
     fail();
   } catch (Type.ConversionException e) {
     assertThat(e)
         .hasMessage(
             "expected value of type 'list(string)' for myexpr, "
                 + "but got \"[(1,2), 3, 4]\" (string)");
   }
 }
Exemplo n.º 4
0
 @Test
 public void testStringListBadElements() throws Exception {
   Object input = Arrays.<Object>asList("foo", "bar", 1);
   try {
     Type.STRING_LIST.convert(input, "argument quux");
     fail();
   } catch (Type.ConversionException e) {
     assertThat(e)
         .hasMessage(
             "expected value of type 'string' for element 2 of argument quux, but got 1 (int)");
   }
 }
Exemplo n.º 5
0
  @Test
  public void testTagConversion() throws Exception {
    assertSameContents(Sets.newHashSet("attribute"), Type.BOOLEAN.toTagSet(true, "attribute"));
    assertSameContents(Sets.newHashSet("noattribute"), Type.BOOLEAN.toTagSet(false, "attribute"));

    assertSameContents(
        Sets.newHashSet("whiskey"), Type.STRING.toTagSet("whiskey", "preferred_cocktail"));

    assertSameContents(
        Sets.newHashSet("cheddar", "ementaler", "gruyere"),
        Type.STRING_LIST.toTagSet(
            Lists.newArrayList("cheddar", "ementaler", "gruyere"), "cheeses"));
  }