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;
/**
* @author Juergen Hoeller
* Can be Cat, Dog, Hamster...
*/
@Entity
@Table(name = "types")
......
......@@ -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 {
......
......@@ -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
*/
......
/*
* 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 {
}
@Test
public void emptyFirstName() {
public void shouldNotValidateWhenFirstNameEmpty() {
LocaleContextHolder.setLocale(Locale.ENGLISH);
Person person = new Person();
......
......@@ -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();
......
......@@ -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
......
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