Skip to content

Instantly share code, notes, and snippets.

@manuelGitHub1
Created May 20, 2022 08:21
Show Gist options
  • Save manuelGitHub1/f8c17392e5446b2abb19d5a86cd817e7 to your computer and use it in GitHub Desktop.
Save manuelGitHub1/f8c17392e5446b2abb19d5a86cd817e7 to your computer and use it in GitHub Desktop.
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