Refactor the code smells that were present according to SonarQube

This commit is contained in:
Marty30 2017-06-21 16:41:04 +02:00
parent 29dc4b634f
commit 029fc4ec4e
10 changed files with 34 additions and 48 deletions

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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");
}
}

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -18,7 +18,6 @@ package org.springframework.samples.petclinic.vet;
import java.util.Collection;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.DataAccessException;
import org.springframework.data.repository.Repository;
import org.springframework.transaction.annotation.Transactional;
@ -40,7 +39,7 @@ public interface VetRepository extends Repository<Vet, Integer> {
*/
@Transactional(readOnly = true)
@Cacheable("vets")
Collection<Vet> findAll() throws DataAccessException;
Collection<Vet> findAll();
}

View file

@ -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;
}
}

View file

@ -17,7 +17,6 @@ package org.springframework.samples.petclinic.visit;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.data.repository.Repository;
import org.springframework.samples.petclinic.model.BaseEntity;
@ -38,7 +37,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);

View file

@ -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();
}
}