OnrampServiceImpl implements OnrampService { @Override public Optional<Onramp> getOnramp(String name) { return Optional.ofNullable(roads.get(name)).map(road -> new OnrampImpl(metrics, kafkaProducer, road)); } @Autowired  OnrampServiceImpl(
      OnrampMetrics metrics,
      @Value("#{store}") Map<String, Road> roads,
      Producer<byte[], byte[]> kafkaProducer); @Override Optional<Onramp> getOnramp(String name);  }
@Test public void nonExistentRoad() throws Exception { when(roadsMock.get(NON_EXISTENT_ROAD)).thenReturn(null); Optional<Onramp> onramp = underTest.getOnramp(NON_EXISTENT_ROAD); assertFalse(onramp.isPresent()); }
@Test(expected = RuntimeException.class) public void storeException() throws Exception { when(roadsMock.get(TEST_ROAD)).thenThrow(RuntimeException.class); underTest.getOnramp(TEST_ROAD); }
@Test public void roadFound() throws Exception { Road road = new Road(); road.setSchemas(singletonMap(1, new SchemaVersion(SCHEMA, 1, false))); when(roadsMock.get(TEST_ROAD)).thenReturn(road); Optional<Onramp> onramp = underTest.getOnramp(TEST_ROAD); assertTrue(onramp.isPresent()); }