### Question:
WaterSubsystem extends BaseSubsystem<WaterSubsystemModel> { @Override protected void setAttribute(String name, Object value, SubsystemContext<WaterSubsystemModel> context) throws ErrorEventException { String address = (String) value; if(WaterSubsystemCapability.ATTR_PRIMARYWATERHEATER.equals(name)) { Model model = context.models().getModelByAddress(Address.fromString(address)); if(model == null || !model.supports(WaterHeaterCapability.NAMESPACE)) { throw new ErrorEventException(WaterSubsystemErrors.notWaterHeater(address)); } }else if(WaterSubsystemCapability.ATTR_PRIMARYWATERSOFTENER.equals(name)) { Model model = context.models().getModelByAddress(Address.fromString(address)); if(model == null || !model.supports(WaterSoftenerCapability.NAMESPACE)) { throw new ErrorEventException(WaterSubsystemErrors.notWaterSoftener(address)); } } super.setAttribute(name, value, context); }    }### Answer:
@Test public void testClosedValveAdded() { start(); Set<String> closedValves = WaterSubsystemModel.getClosedWaterValves(context.model()); assertEquals(0, closedValves.size()); closeWaterValve(testValve1); closedValves = WaterSubsystemModel.getClosedWaterValves(context.model()); assertEquals(1, closedValves.size()); verifyContainAddresses(closedValves, testValve1); SimpleModel testValve2 = new SimpleModel(ModelFixtures.createWaterValveAttributes()); testValve2.setAttribute(ValveCapability.ATTR_VALVESTATE, ValveCapability.VALVESTATE_CLOSED); store.addModel(testValve2.toMap()); closedValves = WaterSubsystemModel.getClosedWaterValves(context.model()); assertEquals(2, closedValves.size()); verifyContainAddresses(closedValves, testValve1, testValve2); }
@Test public void testClosedValveRemoved() { start(); Set<String> closedValves = WaterSubsystemModel.getClosedWaterValves(context.model()); assertEquals(0, closedValves.size()); closeWaterValve(testValve1); closedValves = WaterSubsystemModel.getClosedWaterValves(context.model()); assertEquals(1, closedValves.size()); verifyContainAddresses(closedValves, testValve1); openWaterValve(testValve1); closedValves = WaterSubsystemModel.getClosedWaterValves(context.model()); assertEquals(0, closedValves.size()); SimpleModel testValve2 = new SimpleModel(ModelFixtures.createWaterValveAttributes()); testValve2.setAttribute(ValveCapability.ATTR_VALVESTATE, ValveCapability.VALVESTATE_CLOSED); store.addModel(testValve2.toMap()); closedValves = WaterSubsystemModel.getClosedWaterValves(context.model()); assertEquals(1, closedValves.size()); verifyContainAddresses(closedValves, testValve2); store.removeModel(testValve2.getAddress()); closedValves = WaterSubsystemModel.getClosedWaterValves(context.model()); assertEquals(0, closedValves.size()); }