@Test public void createsOsStatisticsViaFactory() { Statistics statisticsCreatedByFactory = mock(Statistics.class); when(osStatisticsFactory.create(any(), any(), anyLong(), anyLong(), anyInt(), any())) .thenReturn(statisticsCreatedByFactory); Statistics result = registry.createOsStatistics(type, STATISTICS_TEXT_ID, STATISTICS_NUMERIC_ID, STATISTICS_OS_FLAGS); assertThat(result) .isSameAs(statisticsCreatedByFactory); }
Statistics osStatistics3 = mock(Statistics.class, "os 1"); when(osStatisticsFactory.create(any(), any(), anyLong(), anyLong(), anyInt(), any())) .thenReturn(osStatistics1) .thenReturn(osStatistics2)
@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 osStatistics2 = mock(Statistics.class, "os 2"); Statistics osStatistics3 = mock(Statistics.class, "os 3"); when(osStatisticsFactory.create(any(), any(), anyLong(), anyLong(), anyInt(), any())) .thenReturn(osStatistics1) .thenReturn(osStatistics2)
@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 newOsStatistics(StatisticsType type, long uniqueId, long numericId, String textId, int osStatFlags) { Statistics statistics = osStatisticsFactory.create(type, textId, numericId, uniqueId, osStatFlags, this); registerNewStatistics(statistics); return statistics; }