diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100755 index 0000000000000000000000000000000000000000..d84ed7c2d5a93920390f6fd0f7114f292b052c0f --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,13 @@ +# Required metadata +sonar.projectKey=java-sonar-runner-simple +sonar.projectName=Simple Java project analyzed with the SonarQube Runner +sonar.projectVersion=1.0 + +# Comma-separated paths to directories with sources (required) +sonar.sources=src + +# Language +sonar.language=java + +# Encoding of the source files +sonar.sourceEncoding=UTF-8 \ No newline at end of file diff --git a/src/main/java/org/springframework/samples/petclinic/model/PetType.java b/src/main/java/org/springframework/samples/petclinic/model/PetType.java index 50cf0399a7702ea2ec46da4c46626c935a045a5e..99adf75917e3c4c900a88f47bdfea62e6efba541 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/PetType.java +++ b/src/main/java/org/springframework/samples/petclinic/model/PetType.java @@ -20,6 +20,7 @@ import javax.persistence.Table; /** * @author Juergen Hoeller + * Can be Cat, Dog, Hamster... */ @Entity @Table(name = "types") diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java index 05f6a24b2a9ee6b164c3576f636e6c3616a03d42..604e8ebf0fcb6dcf1c3a760812355551da70e154 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java @@ -57,7 +57,7 @@ public class JdbcVetRepositoryImpl implements VetRepository { /** * Refresh the cache of Vets that the ClinicService is holding. * - * @see org.springframework.samples.petclinic.model.service.ClinicService#findVets() + * @see org.springframework.samples.petclinic.model.service.ClinicService#shouldFindVets() */ @Override public Collection<Vet> findAll() throws DataAccessException { diff --git a/src/main/java/org/springframework/samples/petclinic/service/ClinicService.java b/src/main/java/org/springframework/samples/petclinic/service/ClinicService.java index e72b5c10fc0bde80a47123e946b90fde0427b007..9365821293247b0bb5af56809b1040bc5ccf9fd1 100644 --- a/src/main/java/org/springframework/samples/petclinic/service/ClinicService.java +++ b/src/main/java/org/springframework/samples/petclinic/service/ClinicService.java @@ -26,7 +26,7 @@ import org.springframework.samples.petclinic.model.Visit; /** - * Mostly used as a facade for all Petclinic controllers + * Mostly used as a facade so all controllers have a single point of entry * * @author Michael Isvy */ diff --git a/src/test/java/org/springframework/samples/petclinic/model/OwnerTests.java b/src/test/java/org/springframework/samples/petclinic/model/OwnerTests.java deleted file mode 100644 index d5044fd789e32ef82501e81c197d4b33ea5ef9e6..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/model/OwnerTests.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2002-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.samples.petclinic.model; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import org.junit.Test; -import org.springframework.transaction.annotation.Transactional; - -/** - * JUnit test for the {@link Owner} class. - * - * @author Ken Krebs - */ -public class OwnerTests { - - @Test - @Transactional - public void testHasPet() { - Owner owner = new Owner(); - Pet fido = new Pet(); - fido.setName("Fido"); - assertNull(owner.getPet("Fido")); - assertNull(owner.getPet("fido")); - owner.addPet(fido); - assertEquals(fido, owner.getPet("Fido")); - assertEquals(fido, owner.getPet("fido")); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java index 9d1e882dd14e3639d8be91da6f9dc3392183d199..0b8c7a7df766c96341a8f7b617d1b01e494b7d0c 100644 --- a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java +++ b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java @@ -32,7 +32,7 @@ public class ValidatorTests { } @Test - public void emptyFirstName() { + public void shouldNotValidateWhenFirstNameEmpty() { LocaleContextHolder.setLocale(Locale.ENGLISH); Person person = new Person(); diff --git a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java index 02a21ac4df632b8314fe6317f104969478303198..d9dc3495526f6b4f6a6d6a26925ad909ce0c08a0 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java @@ -16,6 +16,7 @@ package org.springframework.samples.petclinic.service; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -59,8 +60,7 @@ public abstract class AbstractClinicServiceTests { protected ClinicService clinicService; @Test - @Transactional - public void findOwners() { + public void shouldFindOwners() { Collection<Owner> owners = this.clinicService.findOwnerByLastName("Davis"); assertEquals(2, owners.size()); owners = this.clinicService.findOwnerByLastName("Daviss"); @@ -68,18 +68,18 @@ public abstract class AbstractClinicServiceTests { } @Test - public void findSingleOwner() { + public void shouldFindSingleOwner() { Owner owner1 = this.clinicService.findOwnerById(1); assertTrue(owner1.getLastName().startsWith("Franklin")); + Owner owner10 = this.clinicService.findOwnerById(10); assertEquals("Carlos", owner10.getFirstName()); - assertEquals(owner1.getPets().size(), 1); } @Test @Transactional - public void insertOwner() { + public void shouldInsertOwner() { Collection<Owner> owners = this.clinicService.findOwnerByLastName("Schultz"); int found = owners.size(); Owner owner = new Owner(); @@ -89,24 +89,26 @@ public abstract class AbstractClinicServiceTests { owner.setCity("Wollongong"); owner.setTelephone("4444444444"); this.clinicService.saveOwner(owner); - Assert.assertNotEquals("Owner Id should have been generated", owner.getId().longValue(), 0); + assertNotEquals("Owner Id should have been generated", owner.getId().longValue(), 0); + owners = this.clinicService.findOwnerByLastName("Schultz"); assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size()); } @Test @Transactional - public void updateOwner() throws Exception { + public void shouldUpdateOwner() { Owner o1 = this.clinicService.findOwnerById(1); String old = o1.getLastName(); o1.setLastName(old + "X"); this.clinicService.saveOwner(o1); o1 = this.clinicService.findOwnerById(1); + assertEquals(old + "X", o1.getLastName()); } @Test - public void findPet() { + public void shouldFindPetWithCorrectId() { Collection<PetType> types = this.clinicService.findPetTypes(); Pet pet7 = this.clinicService.findPetById(7); assertTrue(pet7.getName().startsWith("Samantha")); @@ -119,7 +121,7 @@ public abstract class AbstractClinicServiceTests { } @Test - public void getPetTypes() { + public void shouldFindAllPetTypes() { Collection<PetType> petTypes = this.clinicService.findPetTypes(); PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); @@ -130,7 +132,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void insertPet() { + public void shouldInsertPetIntoDatabaseAndGenerateId() { Owner owner6 = this.clinicService.findOwnerById(6); int found = owner6.getPets().size(); Pet pet = new Pet(); @@ -150,7 +152,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void updatePet() throws Exception { + public void sholdUpdatePet() throws Exception { Pet pet7 = this.clinicService.findPetById(7); String old = pet7.getName(); pet7.setName(old + "X"); @@ -160,7 +162,7 @@ public abstract class AbstractClinicServiceTests { } @Test - public void findVets() { + public void shouldFindVets() { Collection<Vet> vets = this.clinicService.findVets(); Vet v1 = EntityUtils.getById(vets, Vet.class, 2); @@ -176,7 +178,7 @@ public abstract class AbstractClinicServiceTests { @Test @Transactional - public void insertVisit() { + public void shouldAddNewVisitForPet() { Pet pet7 = this.clinicService.findPetById(7); int found = pet7.getVisits().size(); Visit visit = new Visit(); diff --git a/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests.java b/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests.java index 295129f32eedb00181bffd2285f4138a9d287dc7..fb29b0b2212429f0fa639f08255120b5ca3df398 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests.java +++ b/src/test/java/org/springframework/samples/petclinic/web/VisitsViewTests.java @@ -59,7 +59,7 @@ public class VisitsViewTests { } @Test - public void getVisitsXml() throws Exception { + public void shouldFindVisitsInXmlFormat() throws Exception { ResultActions actions = this.mockMvc.perform(get("/vets.xml").accept(MediaType.TEXT_XML)); actions.andDo(print()); // action is logged into the console