SavedSnapshotService extends AbstractSavedSearchService<SavedSnapshot, SavedSnapshot.Builder> { @Override public SavedSnapshot build(final SavedSearch<?, ?> search) throws AciErrorException { final List<StateTokenAndResultCount> stateTokensList = Arrays.asList( getStateTokenAndResultCount(search, false), getStateTokenAndResultCount(search, true) ); final Set<TypedStateToken> stateTokens = new HashSet<>(); for(final StateTokenAndResultCount listToken : stateTokensList) { final TypedStateToken token = listToken.getTypedStateToken(); stateTokens.add(token); } final long resultCount = stateTokensList.get(0).getResultCount(); return new SavedSnapshot.Builder(search) .setStateTokens(stateTokens) .setResultCount(resultCount) .build(); } @Autowired  SavedSnapshotService(final SavedSearchRepository<SavedSnapshot, SavedSnapshot.Builder> savedSnapshotRepository,
                                final SharedToUserRepository sharedToUserRepository,
                                final SharedToEveryoneRepository sharedToEveryoneRepository,
                                final AuditorAware<UserEntity> userEntityAuditorAware,
                                final TagNameFactory tagNameFactory,
                                final IdolDocumentsService documentsService,
                                final FieldTextParser fieldTextParser,
                                final ObjectFactory<IdolQueryRestrictionsBuilder> queryRestrictionsBuilderFactory); @Override SavedSnapshot build(final SavedSearch<?, ?> search);  }
@Test public void testBuild() { final Set<ConceptClusterPhrase> conceptClusterPhrases = Collections.singleton(new ConceptClusterPhrase("query", true, 1)); final SavedQuery query = new SavedQuery.Builder() .setConceptClusterPhrases(conceptClusterPhrases) .build(); final SavedSnapshot snapshot = service.build(query); Mockito.verify(fieldTextParser).toFieldText(query, true); Mockito.verify(fieldTextParser).toFieldText(query, false); Assert.assertEquals("should copy input properties", conceptClusterPhrases, snapshot.getConceptClusterPhrases()); Assert.assertEquals("should retrieve tokens", new HashSet<>(Arrays.asList(normalToken, promotionsToken)), snapshot.getStateTokens()); }