### Question:
FeatureCollection { public Optional<IFeature> get(String code) { if (this.availableFeatures.containsKey(code)) { return Optional.of(this.availableFeatures.get(code)); } return Optional.empty(); } FeatureCollection();   FeatureCollection(Map<String, IFeature> allFeatures); List<IFeature> list(); Optional<IFeature> get(String code);  }### Answer:
@Test public void get_should_return_the_feature() { IFeature wantedFeature = Mockito.mock(IFeature.class); Mockito.doReturn(true).when(availableFeaturesMock).containsKey("my-feature"); Mockito.doReturn(wantedFeature).when(availableFeaturesMock).get("my-feature"); Optional<IFeature> iFeature = cut.get("my-feature"); Assertions.assertThat(iFeature.isPresent()).isTrue(); Assertions.assertThat(iFeature.get()).isNotNull(); Assertions.assertThat(iFeature.get()).isEqualTo(wantedFeature); }
@Test public void get_should_return_empty_if_not_found() { IFeature wantedFeature = Mockito.mock(IFeature.class); Mockito.doReturn(false).when(availableFeaturesMock).containsKey("nope"); Optional<IFeature> iFeature = cut.get("nope"); Assertions.assertThat(iFeature.isPresent()).isFalse(); Mockito.verify(availableFeaturesMock, Mockito.never()).get(Mockito.anyString()); }