@Override public Collection<String> classNames() { if (this.cache != null) { final Collection<String> cachedNames = this.cache.get(); if (cachedNames != null) { return cachedNames; } } final Collection<String> names = this.child.classNames(); this.cache = new SoftReference<>(names); return names; }
@Override public Collection<String> classNames() { final List<String> arrayList = new ArrayList<>(); for (final ClassPathRoot root : this.roots) { arrayList.addAll(root.classNames()); } return arrayList; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); this.testee = new ClassPath(this.firstComponent, this.secondComponent); when(this.firstComponent.cacheLocation()).thenReturn(Optional.ofNullable("foo")); when(this.firstComponent.classNames()).thenReturn( Collections.singletonList("FooClass")); when(this.secondComponent.cacheLocation()).thenReturn(Optional.ofNullable("bar")); when(this.secondComponent.classNames()).thenReturn( Collections.singletonList("BarClass")); }
@Test public void shouldReturnNamesOfAllClassesKnownByChildren() { when(this.child1.classNames()).thenReturn(Collections.singletonList("Foo")); when(this.child2.classNames()).thenReturn(Collections.singletonList("Bar")); when(this.heavyChild.classNames()).thenReturn(Collections.singletonList("Heavy")); assertThat(this.testee.classNames()).containsOnly("Foo", "Bar", "Heavy"); }
@Test public void shouldNotQueryHeavyRootsForClassesTheyDoNotContain() throws IOException { when(this.child1.classNames()).thenReturn(Collections.singletonList("Foo")); when(this.heavyChild.classNames()).thenReturn(Collections.singletonList("Heavy")); when(this.child2.classNames()).thenReturn(Collections.singletonList("Bar")); this.testee.getData("Bar"); verify(this.heavyChild,never()).getData("Bar"); this.testee.getData("Heavy"); verify(this.heavyChild).getData("Heavy"); }
@Override public Collection<String> classNames() { final List<String> arrayList = new ArrayList<>(); for (final ClassPathRoot root : this.roots) { arrayList.addAll(root.classNames()); } return arrayList; }
@Override public Collection<String> classNames() { if (this.cache != null) { final Collection<String> cachedNames = this.cache.get(); if (cachedNames != null) { return cachedNames; } } final Collection<String> names = this.child.classNames(); this.cache = new SoftReference<>(names); return names; }