InsetOperator extends Operator<T> { @Override public Flag.FlagResultStatus appliesTo(@Nullable T value) { if (null != values) { for (T v : values) { if (v.equals(value)) return Flag.FlagResultStatus.ENABLED; } } return Flag.FlagResultStatus.DISABLED; } InsetOperator(String name, List<T> values); @Override Flag.FlagResultStatus appliesTo(@Nullable T value);  }
@Test public void testStringInsetOperator() throws Exception { List<String> values = new ArrayList<>(); values.add("1"); values.add("2"); values.add("3"); values.add("4"); values.add("5"); InsetOperator<String> insetOperator = new InsetOperator<>("in-set", values); assertEquals(Flag.FlagResultStatus.ENABLED, insetOperator.appliesTo("2")); assertEquals(Flag.FlagResultStatus.DISABLED, insetOperator.appliesTo("6")); }
@Test public void testIntegerInsetOperator() throws Exception { List<Integer> values = new ArrayList<>(); values.add(1); values.add(2); values.add(3); values.add(4); values.add(5); InsetOperator<Integer> insetOperator = new InsetOperator<>("in-set", values); assertEquals(Flag.FlagResultStatus.ENABLED, insetOperator.appliesTo(2)); assertEquals(Flag.FlagResultStatus.DISABLED, insetOperator.appliesTo(6)); }
@Test public void testEmptyInsetOperator() throws Exception { List<Integer> values = new ArrayList<>(); InsetOperator<Integer> insetOperator = new InsetOperator<>("in-set", values); assertEquals(Flag.FlagResultStatus.DISABLED, insetOperator.appliesTo(2)); assertEquals(Flag.FlagResultStatus.DISABLED, insetOperator.appliesTo(6)); }
@Test public void testWithNullListInsetOperator() throws Exception { InsetOperator<Integer> insetOperator = new InsetOperator<>("in-set", null); assertEquals(Flag.FlagResultStatus.DISABLED, insetOperator.appliesTo(2)); assertEquals(Flag.FlagResultStatus.DISABLED, insetOperator.appliesTo(6)); }