Use consistent exception messages in Assert calls
Update `Assert` calls to consistently use messages of the form "'item' must [not] ...". Closes gh-43780
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,8 +70,8 @@ public class Review implements Serializable {
|
||||
}
|
||||
|
||||
public Review(Hotel hotel, int index, ReviewDetails details) {
|
||||
Assert.notNull(hotel, "Hotel must not be null");
|
||||
Assert.notNull(details, "Details must not be null");
|
||||
Assert.notNull(hotel, "'hotel' must not be null");
|
||||
Assert.notNull(details, "'details' must not be null");
|
||||
this.hotel = hotel;
|
||||
this.index = index;
|
||||
this.rating = details.getRating();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ public class CitySearchCriteria implements Serializable {
|
||||
}
|
||||
|
||||
public CitySearchCriteria(String name) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
Assert.notNull(name, "'name' must not be null");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,36 +41,31 @@ class CityServiceImpl implements CityService {
|
||||
|
||||
@Override
|
||||
public Page<City> findCities(CitySearchCriteria criteria, Pageable pageable) {
|
||||
|
||||
Assert.notNull(criteria, "Criteria must not be null");
|
||||
Assert.notNull(criteria, "'criteria' must not be null");
|
||||
String name = criteria.getName();
|
||||
|
||||
if (!StringUtils.hasLength(name)) {
|
||||
return this.cityRepository.findAll(null);
|
||||
}
|
||||
|
||||
String country = "";
|
||||
int splitPos = name.lastIndexOf(',');
|
||||
|
||||
if (splitPos >= 0) {
|
||||
country = name.substring(splitPos + 1);
|
||||
name = name.substring(0, splitPos);
|
||||
}
|
||||
|
||||
return this.cityRepository.findByNameContainingAndCountryContainingAllIgnoringCase(name.trim(), country.trim(),
|
||||
pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public City getCity(String name, String country) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
Assert.notNull(country, "Country must not be null");
|
||||
Assert.notNull(name, "'name' must not be null");
|
||||
Assert.notNull(country, "'country' must not be null");
|
||||
return this.cityRepository.findByNameAndCountryAllIgnoringCase(name, country);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<HotelSummary> getHotels(City city, Pageable pageable) {
|
||||
Assert.notNull(city, "City must not be null");
|
||||
Assert.notNull(city, "'city' must not be null");
|
||||
return this.hotelRepository.findByCity(city, pageable);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,20 +48,20 @@ class HotelServiceImpl implements HotelService {
|
||||
|
||||
@Override
|
||||
public Hotel getHotel(City city, String name) {
|
||||
Assert.notNull(city, "City must not be null");
|
||||
Assert.hasLength(name, "Name must not be empty");
|
||||
Assert.notNull(city, "'city' must not be null");
|
||||
Assert.hasLength(name, "'name' must not be empty");
|
||||
return this.hotelRepository.findByCityAndName(city, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Review> getReviews(Hotel hotel, Pageable pageable) {
|
||||
Assert.notNull(hotel, "Hotel must not be null");
|
||||
Assert.notNull(hotel, "'hotel' must not be null");
|
||||
return this.reviewRepository.findByHotel(hotel, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Review getReview(Hotel hotel, int reviewNumber) {
|
||||
Assert.notNull(hotel, "Hotel must not be null");
|
||||
Assert.notNull(hotel, "'hotel' must not be null");
|
||||
return this.reviewRepository.findByHotelAndIndex(hotel, reviewNumber);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,7 +30,7 @@ public class CitySearchCriteria implements Serializable {
|
||||
}
|
||||
|
||||
public CitySearchCriteria(String name) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
Assert.notNull(name, "'name' must not be null");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,8 +46,8 @@ public class User {
|
||||
}
|
||||
|
||||
public User(String username, VehicleIdentificationNumber vin) {
|
||||
Assert.hasLength(username, "Username must not be empty");
|
||||
Assert.notNull(vin, "VIN must not be null");
|
||||
Assert.hasLength(username, "'username' must not be empty");
|
||||
Assert.notNull(vin, "'vin' must not be null");
|
||||
this.username = username;
|
||||
this.vin = vin;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2022 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,8 +28,8 @@ public final class VehicleIdentificationNumber {
|
||||
private final String vin;
|
||||
|
||||
public VehicleIdentificationNumber(String vin) {
|
||||
Assert.notNull(vin, "VIN must not be null");
|
||||
Assert.isTrue(vin.length() == 17, "VIN must be exactly 17 characters");
|
||||
Assert.notNull(vin, "'vin' must not be null");
|
||||
Assert.isTrue(vin.length() == 17, "'vin' must be exactly 17 characters");
|
||||
this.vin = vin;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,7 +46,7 @@ public class RemoteVehicleDetailsService implements VehicleDetailsService {
|
||||
@Override
|
||||
public VehicleDetails getVehicleDetails(VehicleIdentificationNumber vin)
|
||||
throws VehicleIdentificationNumberNotFoundException {
|
||||
Assert.notNull(vin, "VIN must not be null");
|
||||
Assert.notNull(vin, "'vin' must not be null");
|
||||
logger.debug("Retrieving vehicle data for: " + vin);
|
||||
try {
|
||||
return this.restTemplate.getForObject("/vehicle/{vin}/details", VehicleDetails.class, vin);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,8 +34,8 @@ public class VehicleDetails {
|
||||
|
||||
@JsonCreator
|
||||
public VehicleDetails(@JsonProperty("make") String make, @JsonProperty("model") String model) {
|
||||
Assert.notNull(make, "Make must not be null");
|
||||
Assert.notNull(model, "Model must not be null");
|
||||
Assert.notNull(make, "'make' must not be null");
|
||||
Assert.notNull(model, "'model' must not be null");
|
||||
this.make = make;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,7 +44,7 @@ public class UserVehicleService {
|
||||
|
||||
public VehicleDetails getVehicleDetails(String username)
|
||||
throws UserNameNotFoundException, VehicleIdentificationNumberNotFoundException {
|
||||
Assert.notNull(username, "Username must not be null");
|
||||
Assert.notNull(username, "'username' must not be null");
|
||||
User user = this.userRepository.findByUsername(username);
|
||||
if (user == null) {
|
||||
throw new UserNameNotFoundException(username);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,19 +41,19 @@ class UserEntityTests {
|
||||
@Test
|
||||
void createWhenUsernameIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new User(null, VIN))
|
||||
.withMessage("Username must not be empty");
|
||||
.withMessage("'username' must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWhenUsernameIsEmptyShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new User("", VIN))
|
||||
.withMessage("Username must not be empty");
|
||||
.withMessage("'username' must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWhenVinIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new User("sboot", null))
|
||||
.withMessage("VIN must not be null");
|
||||
.withMessage("'vin' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,19 +36,19 @@ class VehicleIdentificationNumberTests {
|
||||
@Test
|
||||
void createWhenVinIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber(null))
|
||||
.withMessage("VIN must not be null");
|
||||
.withMessage("'vin' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWhenVinIsMoreThan17CharsShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber("012345678901234567"))
|
||||
.withMessage("VIN must be exactly 17 characters");
|
||||
.withMessage("'vin' must be exactly 17 characters");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWhenVinIsLessThan17CharsShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new VehicleIdentificationNumber("0123456789012345"))
|
||||
.withMessage("VIN must be exactly 17 characters");
|
||||
.withMessage("'vin' must be exactly 17 characters");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -54,7 +54,7 @@ class RemoteVehicleDetailsServiceTests {
|
||||
@Test
|
||||
void getVehicleDetailsWhenVinIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.service.getVehicleDetails(null))
|
||||
.withMessage("VIN must not be null");
|
||||
.withMessage("'vin' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -59,7 +59,7 @@ class UserVehicleServiceTests {
|
||||
@Test
|
||||
void getVehicleDetailsWhenUsernameIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.service.getVehicleDetails(null))
|
||||
.withMessage("Username must not be null");
|
||||
.withMessage("'username' must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user