mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:15:50 +00:00
Refactor the code smells that were present according to SonarQube
This commit is contained in:
parent
29dc4b634f
commit
99eb71c0cc
10 changed files with 34 additions and 46 deletions
|
@ -21,14 +21,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
|
||||
/**
|
||||
* PetClinic Spring Boot Application.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class PetClinicApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PetClinicApplication.class, args);
|
||||
}
|
||||
|
||||
|
|
|
@ -126,13 +126,13 @@ public class Owner extends Person {
|
|||
* @param name to test
|
||||
* @return true if pet name is already in use
|
||||
*/
|
||||
public Pet getPet(String name, boolean ignoreNew) {
|
||||
name = name.toLowerCase();
|
||||
public Pet getPet(final String name, final boolean ignoreNew) {
|
||||
String lowerCaseName = name.toLowerCase();
|
||||
for (Pet pet : getPetsInternal()) {
|
||||
if (!ignoreNew || !pet.isNew()) {
|
||||
String compName = pet.getName();
|
||||
compName = compName.toLowerCase();
|
||||
if (compName.equals(name)) {
|
||||
if (compName.equals(lowerCaseName)) {
|
||||
return pet;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class OwnerController {
|
|||
}
|
||||
|
||||
@RequestMapping(value = "/owners", method = RequestMethod.GET)
|
||||
public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) {
|
||||
public String processFindForm(final Owner owner, final BindingResult result, final Map<String, Object> model) {
|
||||
|
||||
// allow parameterless GET request for /owners to return all records
|
||||
if (owner.getLastName() == null) {
|
||||
|
@ -93,8 +93,8 @@ class OwnerController {
|
|||
return "owners/findOwners";
|
||||
} else if (results.size() == 1) {
|
||||
// 1 owner found
|
||||
owner = results.iterator().next();
|
||||
return "redirect:/owners/" + owner.getId();
|
||||
Owner founndOwner = results.iterator().next();
|
||||
return "redirect:/owners/" + founndOwner.getId();
|
||||
} else {
|
||||
// multiple owners found
|
||||
model.put("selections", results);
|
||||
|
|
|
@ -31,8 +31,7 @@ class CrashController {
|
|||
|
||||
@RequestMapping(value = "/oups", method = RequestMethod.GET)
|
||||
public String triggerException() {
|
||||
throw new RuntimeException(
|
||||
"Expected: controller used to showcase what " + "happens when an exception is thrown");
|
||||
throw new ExampleException("Expected: controller used to showcase what happens when an exception is thrown");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.springframework.samples.petclinic.system;
|
||||
|
||||
/**
|
||||
* @author Martijn
|
||||
* @since 21-6-2017.
|
||||
*/
|
||||
public class ExampleException extends RuntimeException {
|
||||
public ExampleException(String message) {
|
||||
super(ExampleException.class.getSimpleName() + ": " + message);
|
||||
}
|
||||
|
||||
protected ExampleException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(ExampleException.class.getSimpleName() + ": " + message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
|
@ -31,11 +31,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
@Controller
|
||||
class VetController {
|
||||
|
||||
private final VetRepository vets;
|
||||
private final VetRepository vetRepository;
|
||||
|
||||
@Autowired
|
||||
public VetController(VetRepository clinicService) {
|
||||
this.vets = clinicService;
|
||||
this.vetRepository = clinicService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = { "/vets.html" })
|
||||
|
@ -43,7 +43,7 @@ class VetController {
|
|||
// Here we are returning an object of type 'Vets' rather than a collection of Vet
|
||||
// objects so it is simpler for Object-Xml mapping
|
||||
Vets vets = new Vets();
|
||||
vets.getVetList().addAll(this.vets.findAll());
|
||||
vets.getVetList().addAll(this.vetRepository.findAll());
|
||||
model.put("vets", vets);
|
||||
return "vets/vetList";
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class VetController {
|
|||
// Here we are returning an object of type 'Vets' rather than a collection of Vet
|
||||
// objects so it is simpler for JSon/Object mapping
|
||||
Vets vets = new Vets();
|
||||
vets.getVetList().addAll(this.vets.findAll());
|
||||
vets.getVetList().addAll(this.vetRepository.findAll());
|
||||
return vets;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public interface VetRepository extends Repository<Vet, Integer> {
|
|||
*/
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable("vets")
|
||||
Collection<Vet> findAll() throws DataAccessException;
|
||||
Collection<Vet> findAll();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -30,14 +30,14 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
@XmlRootElement
|
||||
public class Vets {
|
||||
|
||||
private List<Vet> vets;
|
||||
private List<Vet> vetList;
|
||||
|
||||
@XmlElement
|
||||
public List<Vet> getVetList() {
|
||||
if (vets == null) {
|
||||
vets = new ArrayList<>();
|
||||
if (vetList == null) {
|
||||
vetList = new ArrayList<>();
|
||||
}
|
||||
return vets;
|
||||
return vetList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public interface VisitRepository extends Repository<Visit, Integer> {
|
|||
* @param visit the <code>Visit</code> to save
|
||||
* @see BaseEntity#isNew
|
||||
*/
|
||||
void save(Visit visit) throws DataAccessException;
|
||||
void save(Visit visit);
|
||||
|
||||
List<Visit> findByPetId(Integer petId);
|
||||
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package nl.utwente.bpsd.selenium;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
/**
|
||||
* @author Martijn
|
||||
* @since 21-6-2017.
|
||||
*/
|
||||
public class FailingIT extends SeleniumBaseIT {
|
||||
public FailingIT() throws MalformedURLException {
|
||||
super();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Category(SeleniumBaseIT.class)
|
||||
@Ignore
|
||||
public void failIT() {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue