Created
May 20, 2022 08:21
-
-
Save manuelGitHub1/f8c17392e5446b2abb19d5a86cd817e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import static org.assertj.core.api.Assertions.assertThat; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.stream.IntStream; | |
import org.assertj.core.api.SoftAssertions; | |
import org.junit.jupiter.api.Test; | |
public class SoftAsserstionsTest { | |
@Test | |
public void test_mealtime() { | |
TimeOut timeOut = new TimeOut(); | |
final List<Meal> meals = timeOut.getMeals(); | |
assertThat(meals).hasSize(25); | |
assertThat(meals.stream().filter(m -> m.type() == Type.MEATY).count()).as("fleisch Gerichte").isEqualTo(6); | |
assertThat(meals.stream().filter(m -> m.type() == Type.VEGETARIAN).count()).as("vegetarische Gerichte").isEqualTo(7); | |
assertThat(meals.stream().filter(m -> m.type() == Type.SALAD).count()).as("Salat").isEqualTo(12); | |
assertThat(timeOut.getDessertCount()).as("Desserts").isEqualTo(30); | |
} | |
enum Type { | |
SALAD, | |
VEGETARIAN, | |
MEATY; | |
} | |
public static class TimeOut { | |
public int getDessertCount() { | |
return 25; | |
} | |
public List<Meal> getMeals() { | |
final List<Meal> meals = new ArrayList<>(); | |
meals.addAll(IntStream.range(0, 5).mapToObj(i -> new Meal(Type.VEGETARIAN)).toList()); | |
meals.addAll(IntStream.range(0, 5).mapToObj(i -> new Meal(Type.MEATY)).toList()); | |
meals.addAll(IntStream.range(0, 5).mapToObj(i -> new Meal(Type.SALAD)).toList()); | |
return meals; | |
} | |
} | |
record Meal(Type type) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment