### Question:
IndexerForSearchSelector { protected boolean checkIndexerHitLimit(Indexer indexer) { Stopwatch stopwatch = Stopwatch.createStarted(); IndexerConfig indexerConfig = indexer.getConfig(); if (!indexerConfig.getHitLimit().isPresent() && !indexerConfig.getDownloadLimit().isPresent()) { return true; } LocalDateTime comparisonTime; LocalDateTime now = LocalDateTime.now(clock); if (indexerConfig.getHitLimitResetTime().isPresent()) { comparisonTime = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()); if (comparisonTime.isAfter(now)) { comparisonTime = comparisonTime.minus(1, ChronoUnit.DAYS); } } else { comparisonTime = now.minus(1, ChronoUnit.DAYS); } if (indexerConfig.getHitLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.SEARCH, indexerConfig.getHitLimit().get(), "API hit"); if (limitExceeded) { return false; } } if (indexerConfig.getDownloadLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.NZB, indexerConfig.getDownloadLimit().get(), "download"); if (limitExceeded) { return false; } } logger.debug(LoggingMarkers.PERFORMANCE, "Detection that hit limits were not reached for indexer {} took {}ms", indexer.getName(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); return true; }  IndexerForSearchSelection pickIndexers(SearchRequest searchRequest); static final Pattern SCHEDULER_PATTERN; }### Answer:
@Test public void shouldIgnoreHitLimitIfNotYetReached() { indexerConfigMock.setHitLimit(10); when(queryMock.getResultList()).thenReturn(Collections.emptyList()); boolean result = testee.checkIndexerHitLimit(indexer); assertTrue(result); verify(entityManagerMock).createNativeQuery(anyString()); }
@Test public void shouldFollowApiHitLimit() { indexerConfigMock.setHitLimit(1); when(queryMock.getResultList()).thenReturn(Arrays.asList(Timestamp.from(Instant.now().minus(10, ChronoUnit.MILLIS)))); boolean result = testee.checkIndexerHitLimit(indexer); assertFalse(result); verify(entityManagerMock).createNativeQuery(anyString()); }
@Test public void shouldIgnoreDownloadLimitIfNotYetReached() { indexerConfigMock.setDownloadLimit(10); when(queryMock.getResultList()).thenReturn(Arrays.asList(Timestamp.from(Instant.now().minus(10, ChronoUnit.MILLIS)))); boolean result = testee.checkIndexerHitLimit(indexer); assertTrue(result); }
@Test public void shouldIgnoreHitAndDownloadLimitIfNoneAreSet() { indexerConfigMock.setHitLimit(null); indexerConfigMock.setDownloadLimit(null); testee.checkIndexerHitLimit(indexer); verify(nzbDownloadRepository, never()).findBySearchResultIndexerOrderByTimeDesc(any(), any()); verify(indexerApiAccessRepository, never()).findByIndexerOrderByTimeDesc(any(), any()); }