### Question:
BackendProviderSet extends AbstractSet<TraceeBackendProvider> { @Override public int size() { final Collection<TraceeBackendProvider> strongRefList = createStrongView(values); determineValidity(strongRefList); if (valid) { return strongRefList.size(); } return 0; } BackendProviderSet(Set<TraceeBackendProvider> elements); @Override Iterator<TraceeBackendProvider> iterator(); @Override int size();  }### Answer:
@Test public void shouldReturnSize() { final Set<TraceeBackendProvider> providers = Sets.newSet(mock(TraceeBackendProvider.class), mock(TraceeBackendProvider.class)); final BackendProviderSet out = new BackendProviderSet(providers); assertThat(out.size(), equalTo(2)); }
@Test public void shouldHandleEmptySet() { final Set<TraceeBackendProvider> providers = Sets.newSet(); final BackendProviderSet out = new BackendProviderSet(providers); assertThat(out.size(), equalTo(0)); }
@Test public void shouldReturnEmptySetIfOneElementWasDetached() throws Exception { final BackendProviderSet traceeBackendProviders = buildProviderSetWithOneDetachedProvider(); assertThat(traceeBackendProviders.size(), equalTo(0)); }
@Test public void backendProviderSetShouldInternallyInvalidateState() throws Exception { final BackendProviderSet traceeBackendProviders = buildProviderSetWithOneDetachedProvider(); final Field validField = Whitebox.getField(BackendProviderSet.class, "valid"); traceeBackendProviders.size(); assertThat(validField.getBoolean(traceeBackendProviders), is(false)); traceeBackendProviders.size(); assertThat(validField.getBoolean(traceeBackendProviders), is(false)); }