### Question:
MetricResources { Optional<Map<String, List<String>>> getTags(Map<String, List<String>> tags) { if (configuration.isAuthEnabled()) { if (tags == null) { tags = Maps.newHashMap(); } String tenantId = getTenantId(); tags.put("zenoss_tenant_id", Lists.newArrayList(tenantId)); } return Optional.fromNullable(tags); } MetricResources();  MetricResources(AppConfiguration configuration, ZappSecurity security, MetricServiceAPI api); @POST @Timed @Consumes(MediaType.APPLICATION_JSON) Response query(PerformanceQuery query); @OPTIONS Response handleOptions(@HeaderParam("Access-Control-Request-Headers")  String request);  }### Answer:
@Test public void testGetTagAuth() { when(configuration.isAuthEnabled()).thenReturn(true); Subject subject = mock( Subject.class); when(security.getSubject()).thenReturn( subject); PrincipalCollection collection = mock(PrincipalCollection.class); when(subject.getPrincipals()).thenReturn( collection); ZenossTenant tenant = ZenossTenant.get( "1"); when(collection.oneByType( ZenossTenant.class)).thenReturn(tenant); Map<String, List<String>> _tags = Maps.newHashMap(); _tags.put( "zenoss_tenant_id", Lists.newArrayList( "1")); Optional<Map<String, List<String>>> tags = Optional.fromNullable(_tags); assertEquals(tags, new MetricResources(configuration, security, api).getTags(null)); }
@Test public void testGetTagNoAuth() { Optional<Map<String, List<String>>> tags = Optional.fromNullable(null); when(configuration.isAuthEnabled()).thenReturn(false); assertEquals(tags, new MetricResources(configuration, security, api).getTags(null)); }