CombinedFeedService implements CrudService<CombinedFeed> { @Override public CombinedFeed save(CombinedFeed insertedFeed) { String entityId = idGenerator.getId(); CombinedFeed.CombinedFeedBuilder feedBuilder = of(insertedFeed).id(entityId).feedEntries(null); if (insertedFeed.getRefreshPeriod() == 0) { feedBuilder.refreshPeriod(Long.parseLong(defaultRefreshPeriod)); } CombinedFeed combinedFeed = feedBuilder.build(); datastore.put(entityId, combinedFeed); return combinedFeed; } @Inject  CombinedFeedService(InMemoryDataStore datastore, IdGenerator idGenerator,
                               @Named(DEFAULT_REFRESH_PERIOD) String defaultRefreshPeriod); @Override CombinedFeed save(CombinedFeed insertedFeed); @Override Serializable delete(String feedId); @Override CombinedFeed update(CombinedFeed feed); @Override CombinedFeed get(String feedId); @Override List<CombinedFeed> getAll();  }
@Test public void testSaveWithRefreshPeriod() { String id = "1"; CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, "http: .title("title").description("description").refreshPeriod(10).build(); expect(idGenerator.getId()).andReturn(id); expect(datastore.put(eq(id), eq(feed))).andReturn(null); replayAll(); CombinedFeed actual = testedClass.save(feed); verifyAll(); assertEquals(feed, actual); }
@Test public void testSaveWithoutRefreshPeriod() { String id = "1"; CombinedFeed feed = new CombinedFeed.CombinedFeedBuilder(id, "http: .title("title").description("description").build(); CombinedFeed expected = CombinedFeed.CombinedFeedBuilder.of(feed) .refreshPeriod(Long.parseLong(DEFAULT_REFRESH_PERIOD)).build(); expect(idGenerator.getId()).andReturn(id); expect(datastore.put(eq(id), eq(expected))).andReturn(null); replayAll(); CombinedFeed actual = testedClass.save(feed); verifyAll(); assertEquals(expected, actual); }