예제 #1
0
 /** Tests that non-label selector keys trigger an exception. */
 @Test
 public void testSelectorKeyIsNotALabel() throws Exception {
   Object input =
       ImmutableMap.of("not a label", "//a:a", Type.Selector.DEFAULT_CONDITION_KEY, "whatever");
   try {
     new Type.Selector<Label>(input, null, currentRule, Type.LABEL);
     fail("Expected Selector instantiation to fail since the key isn't a label");
   } catch (ConversionException e) {
     assertThat(e.getMessage()).contains("invalid label 'not a label'");
   }
 }
예제 #2
0
 /** Tests that {@link Type#convert} fails on selector inputs. */
 @Test
 public void testConvertDoesNotAcceptSelectables() throws Exception {
   Object selectableInput =
       SelectorList.of(
           new SelectorValue(
               ImmutableMap.of("//conditions:a", Arrays.asList("//a:a1", "//a:a2"))));
   try {
     Type.LABEL_LIST.convert(selectableInput, null, currentRule);
     fail("Expected conversion to fail on a selectable input");
   } catch (ConversionException e) {
     assertThat(e.getMessage()).contains("expected value of type 'list(label)'");
   }
 }
예제 #3
0
 @Test
 public void testSelectorListMixedTypes() throws Exception {
   Object selector1 =
       new SelectorValue(ImmutableMap.of("//conditions:a", ImmutableList.of("//a:a")));
   Object selector2 = new SelectorValue(ImmutableMap.of("//conditions:b", "//b:b"));
   try {
     new Type.SelectorList<>(
         ImmutableList.of(selector1, selector2), null, currentRule, Type.LABEL_LIST);
     fail("Expected SelectorList initialization to fail on mixed element types");
   } catch (ConversionException e) {
     assertThat(e.getMessage()).contains("expected value of type 'list(label)'");
   }
 }