### Question:
BaseSubsystem extends AnnotatedSubsystem<M> { protected void setAttribute(String name, Object value, SubsystemContext<M> context) throws ErrorEventException { NamespacedKey key = NamespacedKey.parse(name); String attributeName = key.getNamedRepresentation(); AttributeDefinition ad = registry.getAttribute(attributeName); if(ad == null || !ad.isWritable()) { context.logger().debug("Received set for unrecognized attribute {}", name); ErrorEvent error = Errors.unsupportedAttribute(name); throw new ErrorEventException(error); } if(key.isInstanced()) { if(!context.model().hasInstanceOf(key.getInstance(), key.getNamespace())) { context.logger().debug("Received set for unsupported instance attribute {}", name); ErrorEvent error = Errors.unsupportedAttribute(name); throw new ErrorEventException(error); } } else { if(!context.model().getCapabilities().contains(key.getNamespace())) { context.logger().debug("Received set for unsupported attribute {}", name); ErrorEvent error = Errors.unsupportedAttribute(name); throw new ErrorEventException(error); } } if(ad.hasMinMax()) { Errors.assertValidRequest(ad.isInRange(value), String.format("Attribute %s must be between %s and %s", ad.getName(), ad.getMin(), ad.getMax())); } context.model().setAttribute(name, ad.getType().coerce(value)); }  @Inject void setDefinitionRegistry(DefinitionRegistry registry); @Request(Capability.CMD_GET_ATTRIBUTES) MessageBody getAttributes(
         @Named("names") Set<String> names,
         SubsystemContext<M> context
   ); @Request(Capability.CMD_SET_ATTRIBUTES) MessageBody setAttributes(PlatformMessage message, SubsystemContext<M> context); @Request(AddTagsRequest.NAME) void addTags(
         @Named(AddTagsRequest.ATTR_TAGS) Set<String> tags,
         SubsystemContext<M> context
   ); @Request(RemoveTagsRequest.NAME) void removeTags(
         @Named(RemoveTagsRequest.ATTR_TAGS) Set<String> tags,
         SubsystemContext<M> context
   );  }### Answer:
@Test public void testAddTagsWithExisting() { model.setAttribute(Capability.ATTR_TAGS, ImmutableSet.of("tag1", "tag2", "tag3")); Set<String> toAdd = ImmutableSet.of("tag3", "tag4", "tag5"); MessageReceivedEvent event = request( AddTagsRequest .builder() .withTags(toAdd) .build() ); subsystem.onEvent(event, context); assertEquals(1, responses.getValues().size()); { MessageBody response = responses.getValue(); assertEquals(AddTagsResponse.instance(), response); assertEquals( ImmutableSet.of("tag1", "tag2", "tag3", "tag4", "tag5"), model.getAttribute(Capability.ATTR_TAGS)); } }
@Test public void testRemoveAllTags() { Set<String> tags = ImmutableSet.of("tag1", "tag2", "tag3"); model.setAttribute(Capability.ATTR_TAGS, tags); MessageReceivedEvent event = request( RemoveTagsRequest .builder() .withTags(tags) .build() ); subsystem.onEvent(event, context); assertEquals(1, responses.getValues().size()); { MessageBody response = responses.getValue(); assertEquals(RemoveTagsResponse.instance(), response); assertEquals(ImmutableSet.of(), model.getAttribute(Capability.ATTR_TAGS)); } }
@Test public void testRemoveSomeTags() { model.setAttribute(Capability.ATTR_TAGS, ImmutableSet.of("tag1", "tag2", "tag3")); Set<String> toRemove = ImmutableSet.of("tag3", "tag4", "tag5"); MessageReceivedEvent event = request( RemoveTagsRequest .builder() .withTags(toRemove) .build() ); subsystem.onEvent(event, context); assertEquals(1, responses.getValues().size()); { MessageBody response = responses.getValue(); assertEquals(RemoveTagsResponse.instance(), response); assertEquals( ImmutableSet.of("tag1", "tag2"), model.getAttribute(Capability.ATTR_TAGS)); } }