Minor code changes are the following:

-Removed unused variables from few files.
-Added null assertions in some tests.
-Added suppression of unused warning alongside the comments.
-Removed unnecessary throw exceptions.
This commit is contained in:
Mousa Al Bateh 2024-10-03 20:06:42 +02:00
parent 74cbac92fb
commit c8a34fb7e9
9 changed files with 28 additions and 15 deletions

View file

@ -71,15 +71,15 @@ class VisitController {
return visit; return visit;
} }
// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is @SuppressWarnings("unused") // Spring MVC calls method loadPetWithVisit(...) before
// called // initNewVisitForm is called
@GetMapping("/owners/{ownerId}/pets/{petId}/visits/new") @GetMapping("/owners/{ownerId}/pets/{petId}/visits/new")
public String initNewVisitForm() { public String initNewVisitForm() {
return "pets/createOrUpdateVisitForm"; return "pets/createOrUpdateVisitForm";
} }
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is @SuppressWarnings("unused") // Spring MVC calls method loadPetWithVisit(...) before
// called // processNewVisitForm is called
@PostMapping("/owners/{ownerId}/pets/{petId}/visits/new") @PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
public String processNewVisitForm(@ModelAttribute Owner owner, @PathVariable int petId, @Valid Visit visit, public String processNewVisitForm(@ModelAttribute Owner owner, @PathVariable int petId, @Valid Visit visit,
BindingResult result, RedirectAttributes redirectAttributes) { BindingResult result, RedirectAttributes redirectAttributes) {

View file

@ -57,10 +57,6 @@ public class Vet extends Person {
return this.specialties; return this.specialties;
} }
protected void setSpecialtiesInternal(Set<Specialty> specialties) {
this.specialties = specialties;
}
@XmlElement @XmlElement
public List<Specialty> getSpecialties() { public List<Specialty> getSpecialties() {
List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal()); List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal());

View file

@ -58,7 +58,7 @@ class MySqlIntegrationTests {
private RestTemplateBuilder builder; private RestTemplateBuilder builder;
@Test @Test
void testFindAll() throws Exception { void testFindAll() {
vets.findAll(); vets.findAll();
vets.findAll(); // served from cache vets.findAll(); // served from cache
} }

View file

@ -44,7 +44,7 @@ public class PetClinicIntegrationTests {
private RestTemplateBuilder builder; private RestTemplateBuilder builder;
@Test @Test
void testFindAll() throws Exception { void testFindAll() {
vets.findAll(); vets.findAll();
vets.findAll(); // served from cache vets.findAll(); // served from cache
} }

View file

@ -17,6 +17,7 @@
package org.springframework.samples.petclinic; package org.springframework.samples.petclinic;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.util.Arrays; import java.util.Arrays;
@ -114,7 +115,20 @@ public class PostgresIntegrationTests {
Arrays.sort(names); Arrays.sort(names);
for (String name : names) { for (String name : names) {
String resolved = environment.getProperty(name); String resolved = environment.getProperty(name);
String value = source.getProperty(name).toString();
if (resolved == null) {
fail("resolved property named {0} was expecting a string but is null.", name);
return;
}
Object sourceProperty = source.getProperty(name);
if (sourceProperty == null || sourceProperty.toString() == null) {
fail("source property named {0} was expecting a string value but is null.", name);
return;
}
String value = sourceProperty.toString();
if (resolved.equals(value)) { if (resolved.equals(value)) {
log.info(name + "=" + resolved); log.info(name + "=" + resolved);
} }

View file

@ -68,7 +68,7 @@ class PetTypeFormatterTests {
} }
@Test @Test
void shouldThrowParseException() throws ParseException { void shouldThrowParseException() {
given(this.pets.findPetTypes()).willReturn(makePetTypes()); given(this.pets.findPetTypes()).willReturn(makePetTypes());
Assertions.assertThrows(ParseException.class, () -> { Assertions.assertThrows(ParseException.class, () -> {
petTypeFormatter.parse("Fish", Locale.ENGLISH); petTypeFormatter.parse("Fish", Locale.ENGLISH);

View file

@ -205,8 +205,6 @@ class ClinicServiceTests {
owner6.addVisit(pet7.getId(), visit); owner6.addVisit(pet7.getId(), visit);
this.owners.save(owner6); this.owners.save(owner6);
owner6 = this.owners.findById(6);
assertThat(pet7.getVisits()) // assertThat(pet7.getVisits()) //
.hasSize(found + 1) // .hasSize(found + 1) //
.allMatch(value -> value.getId() != null); .allMatch(value -> value.getId() != null);

View file

@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
// luck ((plain(st) UNIT test)! :) // luck ((plain(st) UNIT test)! :)
class CrashControllerTests { class CrashControllerTests {
CrashController testee = new CrashController(); final CrashController testee = new CrashController();
@Test @Test
void testTriggerException() { void testTriggerException() {

View file

@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.util.SerializationUtils; import org.springframework.util.SerializationUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
/** /**
* @author Dave Syer * @author Dave Syer
@ -33,6 +34,10 @@ class VetTests {
vet.setId(123); vet.setId(123);
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
Vet other = (Vet) SerializationUtils.deserialize(SerializationUtils.serialize(vet)); Vet other = (Vet) SerializationUtils.deserialize(SerializationUtils.serialize(vet));
if (other == null) {
fail("other expected value but is null.");
return;
}
assertThat(other.getFirstName()).isEqualTo(vet.getFirstName()); assertThat(other.getFirstName()).isEqualTo(vet.getFirstName());
assertThat(other.getLastName()).isEqualTo(vet.getLastName()); assertThat(other.getLastName()).isEqualTo(vet.getLastName());
assertThat(other.getId()).isEqualTo(vet.getId()); assertThat(other.getId()).isEqualTo(vet.getId());