### Question:
SgtGeneratorImpl { public java.util.Optional<Sgt> generateNextSgt(SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> templateCache) { return sgtRange.flatMap(range -> findTopUsedSgt(templateCache.keySet(), range.lowerEndpoint()) .map(topUsedSgt -> incrementSafely(range, topUsedSgt)) ); } SgtGeneratorImpl(final SgtGeneratorConfig sgtGenerator); java.util.Optional<Sgt> generateNextSgt(SimpleCachedDao<Sgt, EndpointPolicyTemplateBySgt> templateCache);  }### Answer:
@Test public void testGenerateNextSgt_noData() throws Exception { final Optional<Sgt> sgt = generator.generateNextSgt(templateDao); Assert.assertTrue(sgt.isPresent()); Assert.assertEquals(10, sgt.get().getValue().intValue()); }
@Test public void testGenerateNextSgt_topIsAboveLimit() throws Exception { sgts.add(new Sgt(20)); final Optional<Sgt> sgt = generator.generateNextSgt(templateDao); Assert.assertFalse(sgt.isPresent()); }
@Test public void testGenerateNextSgt_topIsBelowLimit() throws Exception { sgts.add(new Sgt(9)); final Optional<Sgt> sgt = generator.generateNextSgt(templateDao); Assert.assertTrue(sgt.isPresent()); Assert.assertEquals(10, sgt.get().getValue().intValue()); }
@Test public void testGenerateNextSgt_withinLimits() throws Exception { sgts.add(new Sgt(10)); final Optional<Sgt> sgt = generator.generateNextSgt(templateDao); Assert.assertTrue(sgt.isPresent()); Assert.assertEquals(11, sgt.get().getValue().intValue()); }