Bindings { public void addBinding(String zoneName, List<Fragment> fragments, Mode mode) { if (zoneName == null) { throw new IllegalArgumentException("Zone name of a binding cannot be null."); } else if (zoneName.isEmpty()) { throw new IllegalArgumentException("Zone name of a binding cannot be empty."); } else if (!NameUtils.isFullyQualifiedName(zoneName)) { throw new IllegalArgumentException( "Zone name of a binding should be a fully qualified name. Instead found '" + zoneName + "'."); } if (fragments == null) { throw new IllegalArgumentException("Fragments of a binding cannot be null."); } else { for (Fragment fragment : fragments) { if (fragment == null) { throw new IllegalArgumentException("Fragments in the fragments list in a binding cannot be null."); } } } if (mode == null) { throw new IllegalArgumentException("Mode of a binding cannot be null."); } switch (mode) { case prepend: bindings.get(zoneName).addAll(0, fragments); break; case append: bindings.putAll(zoneName, fragments); break; case overwrite: bindings.replaceValues(zoneName, fragments); break; } } Bindings(); void addBinding(String zoneName, List<Fragment> fragments, Mode mode); List<Fragment> getBindings(String zoneName);  }
@Test public void testAddBindingValidation() { Bindings bindings = createBindings(); Assert.assertThrows(IllegalArgumentException.class, () -> bindings.addBinding(null, emptyList(), Bindings.Mode.prepend)); Assert.assertThrows(IllegalArgumentException.class, () -> bindings.addBinding("", emptyList(), Bindings.Mode.append)); Assert.assertThrows(IllegalArgumentException.class, () -> bindings.addBinding("abc", emptyList(), Bindings.Mode.overwrite)); Assert.assertThrows(IllegalArgumentException.class, () -> bindings.addBinding("org.wso2.foo.z1", null, Bindings.Mode.prepend)); Assert.assertThrows(IllegalArgumentException.class, () -> bindings.addBinding("org.wso2.foo.z1", singletonList(null), Bindings.Mode.append)); Assert.assertThrows(IllegalArgumentException.class, () -> bindings.addBinding("org.wso2.foo.z1", emptyList(), null)); }