3 Dateien geändert
1 Dateien umbenannt
| Datei umbenannt von src/main/java/de/gedoplan/seminar/sbt/di/exercise/SbtDiExerciseApplication.java |
| | |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | |
| | | @SpringBootApplication |
| | | public class SbtDiExerciseApplication { |
| | | public class SbtCoreExerciseApplication { |
| | | |
| | | public static void main(String[] args) { |
| | | SpringApplication.run(SbtDiExerciseApplication.class, args); |
| | | SpringApplication.run(SbtCoreExerciseApplication.class, args); |
| | | } |
| | | |
| | | } |
| | |
| | | package de.gedoplan.seminar.sbt.di.exercise.service; |
| | | |
| | | import de.gedoplan.seminar.sbt.di.exercise.domain.Beverage; |
| | | import de.gedoplan.seminar.sbt.di.exercise.domain.Cocktail; |
| | | import de.gedoplan.seminar.sbt.di.exercise.exception.OutOfStockException; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static java.util.function.Predicate.not; |
| | | |
| | | @Component |
| | | public class IngredientService { |
| | | |
| | | public boolean isAvailable(String id, double amount) { |
| | | public List<Beverage> beveragesNotAvailable(Cocktail cocktail) { |
| | | return cocktail.getIngredients().entrySet().stream() |
| | | .filter(not(e -> isAvailable(e.getKey(), e.getValue()))) |
| | | .map(Map.Entry::getKey) |
| | | .toList(); |
| | | } |
| | | |
| | | public boolean isAvailable(Beverage beverage, double amount) { |
| | | // Dummy check: Anything but rum is available |
| | | return !"RUM".equals(id); |
| | | return !"RUM".equals(beverage.getId()); |
| | | } |
| | | } |
| | |
| | | @Test |
| | | public void testFiltersNonAlcEmpty() throws Exception { |
| | | mockMvc.perform(get("/api/bar/nonalc")) |
| | | .andExpect(content().string("")); |
| | | .andExpect(jsonPath("$.size()",is(0))); |
| | | } |
| | | |
| | | @Test |
| | |
| | | |
| | | |
| | | mockMvc.perform(get("/api/methodCount")) |
| | | .andExpect(jsonPath("$.findAll").value(2)); |
| | | .andExpect(jsonPath("$.getCocktails").value(1)); |
| | | |
| | | mockMvc.perform(get("/api/bar/cocktails")) |
| | | .andExpect(status().isOk()); |
| | | |
| | | mockMvc.perform(get("/api/methodCount")) |
| | | .andExpect(jsonPath("$.findAll").value(4)); |
| | | .andExpect(jsonPath("$.getCocktails").value(2)); |
| | | } |
| | | |
| | | } |