@Test public void createsAtomicStatisticsViaFactory() { Statistics statisticsCreatedByFactory = mock(Statistics.class); when(atomicStatisticsFactory.create(any(), any(), anyLong(), anyLong(), any())) .thenReturn(statisticsCreatedByFactory); Statistics result = registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID); assertThat(result) .isSameAs(statisticsCreatedByFactory); }
.thenReturn(osStatistics3); when(atomicStatisticsFactory.create(any(), any(), anyLong(), anyLong(), any())) .thenReturn(atomicStatistics1) .thenReturn(atomicStatistics2)
@Test public void incrementsModificationCountOnEachCreationAndDestruction() { Statistics osStatistics = mock(Statistics.class, "os"); Statistics atomicStatistics = mock(Statistics.class, "atomic"); when(osStatisticsFactory.create(any(), any(), anyLong(), anyLong(), anyInt(), any())) .thenReturn(osStatistics); when(atomicStatisticsFactory.create(any(), any(), anyLong(), anyLong(), any())) .thenReturn(atomicStatistics); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID); assertThat(registry.getStatListModCount()) .as("modification count after first modification") .isEqualTo(1); registry.createOsStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID, STATISTICS_OS_FLAGS); assertThat(registry.getStatListModCount()) .as("modification count after second modification") .isEqualTo(2); registry.destroyStatistics(osStatistics); assertThat(registry.getStatListModCount()) .as("modification count after third modification") .isEqualTo(3); registry.destroyStatistics(atomicStatistics); assertThat(registry.getStatListModCount()) .as("modification count after fourth modification") .isEqualTo(4); }
Statistics atomicStatistics2 = mock(Statistics.class, "atomic 2"); Statistics atomicStatistics3 = mock(Statistics.class, "atomic 3"); when(atomicStatisticsFactory.create(any(), any(), anyLong(), anyLong(), any())) .thenReturn(atomicStatistics1) .thenReturn(atomicStatistics2)
@Test public void incrementsUniqueIdForEachCreatedStatistics() { registry.createOsStatistics(type, STATISTICS_TEXT_ID, 0, 0); verify(osStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0L, 1, 0, registry); registry.createOsStatistics(type, STATISTICS_TEXT_ID, 0, 0); verify(osStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 2, 0, registry); registry.createOsStatistics(type, STATISTICS_TEXT_ID, 0, 0); verify(osStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 3, 0, registry); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, 0); verify(atomicStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 4, registry); registry.createOsStatistics(type, STATISTICS_TEXT_ID, 0, 0); verify(osStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 5, 0, registry); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, 0); verify(atomicStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 6, registry); registry.createAtomicStatistics(type, STATISTICS_TEXT_ID, 0); verify(atomicStatisticsFactory).create(type, STATISTICS_TEXT_ID, 0, 7, registry); }
protected Statistics newAtomicStatistics(StatisticsType type, long uniqueId, long numericId, String textId) { Statistics statistics = atomicStatisticsFactory.create(type, textId, numericId, uniqueId, this); registerNewStatistics(statistics); return statistics; }