Skip to content
Snippets Groups Projects
Commit 5c9ab6bd authored by michaelisvy's avatar michaelisvy
Browse files

test methods:used should/shouldNot

parent 7080682d
No related branches found
No related tags found
No related merge requests found
# 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
...@@ -20,6 +20,7 @@ import javax.persistence.Table; ...@@ -20,6 +20,7 @@ import javax.persistence.Table;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* Can be Cat, Dog, Hamster...
*/ */
@Entity @Entity
@Table(name = "types") @Table(name = "types")
......
...@@ -57,7 +57,7 @@ public class JdbcVetRepositoryImpl implements VetRepository { ...@@ -57,7 +57,7 @@ public class JdbcVetRepositoryImpl implements VetRepository {
/** /**
* Refresh the cache of Vets that the ClinicService is holding. * 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 @Override
public Collection<Vet> findAll() throws DataAccessException { public Collection<Vet> findAll() throws DataAccessException {
......
...@@ -26,7 +26,7 @@ import org.springframework.samples.petclinic.model.Visit; ...@@ -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 * @author Michael Isvy
*/ */
......
/*
* 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"));
}
}
...@@ -32,7 +32,7 @@ public class ValidatorTests { ...@@ -32,7 +32,7 @@ public class ValidatorTests {
} }
@Test @Test
public void emptyFirstName() { public void shouldNotValidateWhenFirstNameEmpty() {
LocaleContextHolder.setLocale(Locale.ENGLISH); LocaleContextHolder.setLocale(Locale.ENGLISH);
Person person = new Person(); Person person = new Person();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.service; package org.springframework.samples.petclinic.service;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
...@@ -59,8 +60,7 @@ public abstract class AbstractClinicServiceTests { ...@@ -59,8 +60,7 @@ public abstract class AbstractClinicServiceTests {
protected ClinicService clinicService; protected ClinicService clinicService;
@Test @Test
@Transactional public void shouldFindOwners() {
public void findOwners() {
Collection<Owner> owners = this.clinicService.findOwnerByLastName("Davis"); Collection<Owner> owners = this.clinicService.findOwnerByLastName("Davis");
assertEquals(2, owners.size()); assertEquals(2, owners.size());
owners = this.clinicService.findOwnerByLastName("Daviss"); owners = this.clinicService.findOwnerByLastName("Daviss");
...@@ -68,18 +68,18 @@ public abstract class AbstractClinicServiceTests { ...@@ -68,18 +68,18 @@ public abstract class AbstractClinicServiceTests {
} }
@Test @Test
public void findSingleOwner() { public void shouldFindSingleOwner() {
Owner owner1 = this.clinicService.findOwnerById(1); Owner owner1 = this.clinicService.findOwnerById(1);
assertTrue(owner1.getLastName().startsWith("Franklin")); assertTrue(owner1.getLastName().startsWith("Franklin"));
Owner owner10 = this.clinicService.findOwnerById(10); Owner owner10 = this.clinicService.findOwnerById(10);
assertEquals("Carlos", owner10.getFirstName()); assertEquals("Carlos", owner10.getFirstName());
assertEquals(owner1.getPets().size(), 1); assertEquals(owner1.getPets().size(), 1);
} }
@Test @Test
@Transactional @Transactional
public void insertOwner() { public void shouldInsertOwner() {
Collection<Owner> owners = this.clinicService.findOwnerByLastName("Schultz"); Collection<Owner> owners = this.clinicService.findOwnerByLastName("Schultz");
int found = owners.size(); int found = owners.size();
Owner owner = new Owner(); Owner owner = new Owner();
...@@ -89,24 +89,26 @@ public abstract class AbstractClinicServiceTests { ...@@ -89,24 +89,26 @@ public abstract class AbstractClinicServiceTests {
owner.setCity("Wollongong"); owner.setCity("Wollongong");
owner.setTelephone("4444444444"); owner.setTelephone("4444444444");
this.clinicService.saveOwner(owner); 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"); owners = this.clinicService.findOwnerByLastName("Schultz");
assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size()); assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size());
} }
@Test @Test
@Transactional @Transactional
public void updateOwner() throws Exception { public void shouldUpdateOwner() {
Owner o1 = this.clinicService.findOwnerById(1); Owner o1 = this.clinicService.findOwnerById(1);
String old = o1.getLastName(); String old = o1.getLastName();
o1.setLastName(old + "X"); o1.setLastName(old + "X");
this.clinicService.saveOwner(o1); this.clinicService.saveOwner(o1);
o1 = this.clinicService.findOwnerById(1); o1 = this.clinicService.findOwnerById(1);
assertEquals(old + "X", o1.getLastName()); assertEquals(old + "X", o1.getLastName());
} }
@Test @Test
public void findPet() { public void shouldFindPetWithCorrectId() {
Collection<PetType> types = this.clinicService.findPetTypes(); Collection<PetType> types = this.clinicService.findPetTypes();
Pet pet7 = this.clinicService.findPetById(7); Pet pet7 = this.clinicService.findPetById(7);
assertTrue(pet7.getName().startsWith("Samantha")); assertTrue(pet7.getName().startsWith("Samantha"));
...@@ -119,7 +121,7 @@ public abstract class AbstractClinicServiceTests { ...@@ -119,7 +121,7 @@ public abstract class AbstractClinicServiceTests {
} }
@Test @Test
public void getPetTypes() { public void shouldFindAllPetTypes() {
Collection<PetType> petTypes = this.clinicService.findPetTypes(); Collection<PetType> petTypes = this.clinicService.findPetTypes();
PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
...@@ -130,7 +132,7 @@ public abstract class AbstractClinicServiceTests { ...@@ -130,7 +132,7 @@ public abstract class AbstractClinicServiceTests {
@Test @Test
@Transactional @Transactional
public void insertPet() { public void shouldInsertPetIntoDatabaseAndGenerateId() {
Owner owner6 = this.clinicService.findOwnerById(6); Owner owner6 = this.clinicService.findOwnerById(6);
int found = owner6.getPets().size(); int found = owner6.getPets().size();
Pet pet = new Pet(); Pet pet = new Pet();
...@@ -150,7 +152,7 @@ public abstract class AbstractClinicServiceTests { ...@@ -150,7 +152,7 @@ public abstract class AbstractClinicServiceTests {
@Test @Test
@Transactional @Transactional
public void updatePet() throws Exception { public void sholdUpdatePet() throws Exception {
Pet pet7 = this.clinicService.findPetById(7); Pet pet7 = this.clinicService.findPetById(7);
String old = pet7.getName(); String old = pet7.getName();
pet7.setName(old + "X"); pet7.setName(old + "X");
...@@ -160,7 +162,7 @@ public abstract class AbstractClinicServiceTests { ...@@ -160,7 +162,7 @@ public abstract class AbstractClinicServiceTests {
} }
@Test @Test
public void findVets() { public void shouldFindVets() {
Collection<Vet> vets = this.clinicService.findVets(); Collection<Vet> vets = this.clinicService.findVets();
Vet v1 = EntityUtils.getById(vets, Vet.class, 2); Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
...@@ -176,7 +178,7 @@ public abstract class AbstractClinicServiceTests { ...@@ -176,7 +178,7 @@ public abstract class AbstractClinicServiceTests {
@Test @Test
@Transactional @Transactional
public void insertVisit() { public void shouldAddNewVisitForPet() {
Pet pet7 = this.clinicService.findPetById(7); Pet pet7 = this.clinicService.findPetById(7);
int found = pet7.getVisits().size(); int found = pet7.getVisits().size();
Visit visit = new Visit(); Visit visit = new Visit();
......
...@@ -59,7 +59,7 @@ public class VisitsViewTests { ...@@ -59,7 +59,7 @@ public class VisitsViewTests {
} }
@Test @Test
public void getVisitsXml() throws Exception { public void shouldFindVisitsInXmlFormat() throws Exception {
ResultActions actions = this.mockMvc.perform(get("/vets.xml").accept(MediaType.TEXT_XML)); ResultActions actions = this.mockMvc.perform(get("/vets.xml").accept(MediaType.TEXT_XML));
actions.andDo(print()); // action is logged into the console actions.andDo(print()); // action is logged into the console
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment