BAEL-7783: Assert properties of custom exceptions with catchThrowableOfType in AssertJ (#16442)

This commit is contained in:
Azhwani
2024-04-27 11:56:24 +02:00
committed by GitHub
parent 267bd54092
commit 54aee18a7f
3 changed files with 60 additions and 1 deletions
@@ -0,0 +1,22 @@
package com.baeldung.assertj.exceptions;
public class CityNotFoundException extends RuntimeException {
private String city;
private String message;
CityNotFoundException(String city, String message) {
this.city = city;
this.message = message;
}
public String getCity() {
return city;
}
@Override
public String getMessage() {
return message;
}
}
@@ -0,0 +1,17 @@
package com.baeldung.assertj.exceptions;
import java.util.Arrays;
import java.util.List;
public final class CityUtils {
private static final List<String> CITIES = Arrays.asList("Tamassint", "London", "Madrid", "New york");
public static String search(String searchedCity) {
return CITIES.stream()
.filter(searchedCity::equals)
.findFirst()
.orElseThrow(() -> new CityNotFoundException(searchedCity, "The specified city is not found"));
}
}