mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 06:45:50 +00:00
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:
parent
74cbac92fb
commit
c8a34fb7e9
9 changed files with 28 additions and 15 deletions
|
@ -71,15 +71,15 @@ class VisitController {
|
|||
return visit;
|
||||
}
|
||||
|
||||
// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is
|
||||
// called
|
||||
@SuppressWarnings("unused") // Spring MVC calls method loadPetWithVisit(...) before
|
||||
// initNewVisitForm is called
|
||||
@GetMapping("/owners/{ownerId}/pets/{petId}/visits/new")
|
||||
public String initNewVisitForm() {
|
||||
return "pets/createOrUpdateVisitForm";
|
||||
}
|
||||
|
||||
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is
|
||||
// called
|
||||
@SuppressWarnings("unused") // Spring MVC calls method loadPetWithVisit(...) before
|
||||
// processNewVisitForm is called
|
||||
@PostMapping("/owners/{ownerId}/pets/{petId}/visits/new")
|
||||
public String processNewVisitForm(@ModelAttribute Owner owner, @PathVariable int petId, @Valid Visit visit,
|
||||
BindingResult result, RedirectAttributes redirectAttributes) {
|
||||
|
|
|
@ -57,10 +57,6 @@ public class Vet extends Person {
|
|||
return this.specialties;
|
||||
}
|
||||
|
||||
protected void setSpecialtiesInternal(Set<Specialty> specialties) {
|
||||
this.specialties = specialties;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<Specialty> getSpecialties() {
|
||||
List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal());
|
||||
|
|
|
@ -58,7 +58,7 @@ class MySqlIntegrationTests {
|
|||
private RestTemplateBuilder builder;
|
||||
|
||||
@Test
|
||||
void testFindAll() throws Exception {
|
||||
void testFindAll() {
|
||||
vets.findAll();
|
||||
vets.findAll(); // served from cache
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class PetClinicIntegrationTests {
|
|||
private RestTemplateBuilder builder;
|
||||
|
||||
@Test
|
||||
void testFindAll() throws Exception {
|
||||
void testFindAll() {
|
||||
vets.findAll();
|
||||
vets.findAll(); // served from cache
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.samples.petclinic;
|
||||
|
||||
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 java.util.Arrays;
|
||||
|
@ -114,7 +115,20 @@ public class PostgresIntegrationTests {
|
|||
Arrays.sort(names);
|
||||
for (String name : names) {
|
||||
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)) {
|
||||
log.info(name + "=" + resolved);
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ class PetTypeFormatterTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowParseException() throws ParseException {
|
||||
void shouldThrowParseException() {
|
||||
given(this.pets.findPetTypes()).willReturn(makePetTypes());
|
||||
Assertions.assertThrows(ParseException.class, () -> {
|
||||
petTypeFormatter.parse("Fish", Locale.ENGLISH);
|
||||
|
|
|
@ -205,8 +205,6 @@ class ClinicServiceTests {
|
|||
owner6.addVisit(pet7.getId(), visit);
|
||||
this.owners.save(owner6);
|
||||
|
||||
owner6 = this.owners.findById(6);
|
||||
|
||||
assertThat(pet7.getVisits()) //
|
||||
.hasSize(found + 1) //
|
||||
.allMatch(value -> value.getId() != null);
|
||||
|
|
|
@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|||
// luck ((plain(st) UNIT test)! :)
|
||||
class CrashControllerTests {
|
||||
|
||||
CrashController testee = new CrashController();
|
||||
final CrashController testee = new CrashController();
|
||||
|
||||
@Test
|
||||
void testTriggerException() {
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
|
@ -33,6 +34,10 @@ class VetTests {
|
|||
vet.setId(123);
|
||||
@SuppressWarnings("deprecation")
|
||||
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.getLastName()).isEqualTo(vet.getLastName());
|
||||
assertThat(other.getId()).isEqualTo(vet.getId());
|
||||
|
|
Loading…
Reference in a new issue