Skip to content

Commit

Permalink
Minor code changes are the following:
Browse files Browse the repository at this point in the history
-Removed unused variables from few files.
-Added null assertions in some tests.
-Removed unnecessary throw exceptions.
  • Loading branch information
mosbat committed Oct 10, 2024
1 parent fc44212 commit 0b2abfe
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ protected Set<Specialty> getSpecialtiesInternal() {
return this.specialties;
}

protected void setSpecialtiesInternal(Set<Specialty> specialties) {
this.specialties = specialties;
}

@XmlElement
public List<Specialty> getSpecialties() {
List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class MySqlIntegrationTests {
private RestTemplateBuilder builder;

@Test
void testFindAll() throws Exception {
void testFindAll() {
vets.findAll();
vets.findAll(); // served from cache
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class PetClinicIntegrationTests {
private RestTemplateBuilder builder;

@Test
void testFindAll() throws Exception {
void testFindAll() {
vets.findAll();
vets.findAll(); // served from cache
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.samples.petclinic;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.util.Arrays;
Expand Down Expand Up @@ -114,7 +115,16 @@ public void printProperties() {
Arrays.sort(names);
for (String name : names) {
String resolved = environment.getProperty(name);
String value = source.getProperty(name).toString();

assertNotNull(resolved, "resolved environment property: " + name + " is null.");

Object sourceProperty = source.getProperty(name);

assertNotNull(sourceProperty, "source property was expecting an object but is null.");

assertNotNull(sourceProperty.toString(), "source property toString() returned null.");

String value = sourceProperty.toString();
if (resolved.equals(value)) {
log.info(name + "=" + resolved);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void shouldParse() throws ParseException {
}

@Test
void shouldThrowParseException() throws ParseException {
void shouldThrowParseException() {
given(this.pets.findPetTypes()).willReturn(makePetTypes());
Assertions.assertThrows(ParseException.class, () -> {
petTypeFormatter.parse("Fish", Locale.ENGLISH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ void shouldAddNewVisitForPet() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// luck ((plain(st) UNIT test)! :)
class CrashControllerTests {

CrashController testee = new CrashController();
final CrashController testee = new CrashController();

@Test
void testTriggerException() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.util.SerializationUtils;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;

/**
Expand Down

0 comments on commit 0b2abfe

Please sign in to comment.