Search in sources :

Example 1 with PetType

use of org.springframework.samples.petclinic.owner.PetType in project spring-petclinic by spring-projects.

the class PetTypeFormatterTests method makePetTypes.

/**
     * Helper method to produce some sample pet types just for test purpose
     *
     * @return {@link Collection} of {@link PetType}
     */
private List<PetType> makePetTypes() {
    List<PetType> petTypes = new ArrayList<>();
    petTypes.add(new PetType() {

        {
            setName("Dog");
        }
    });
    petTypes.add(new PetType() {

        {
            setName("Bird");
        }
    });
    return petTypes;
}
Also used : ArrayList(java.util.ArrayList) PetType(org.springframework.samples.petclinic.owner.PetType)

Example 2 with PetType

use of org.springframework.samples.petclinic.owner.PetType in project spring-petclinic by spring-projects.

the class PetTypeFormatterTests method shouldParse.

@Test
public void shouldParse() throws ParseException {
    Mockito.when(this.pets.findPetTypes()).thenReturn(makePetTypes());
    PetType petType = petTypeFormatter.parse("Bird", Locale.ENGLISH);
    assertEquals("Bird", petType.getName());
}
Also used : PetType(org.springframework.samples.petclinic.owner.PetType) Test(org.junit.Test)

Example 3 with PetType

use of org.springframework.samples.petclinic.owner.PetType in project spring-petclinic by spring-projects.

the class PetControllerTests method setup.

@Before
public void setup() {
    PetType cat = new PetType();
    cat.setId(3);
    cat.setName("hamster");
    given(this.pets.findPetTypes()).willReturn(Lists.newArrayList(cat));
    given(this.owners.findById(TEST_OWNER_ID)).willReturn(new Owner());
    given(this.pets.findById(TEST_PET_ID)).willReturn(new Pet());
}
Also used : Owner(org.springframework.samples.petclinic.owner.Owner) Pet(org.springframework.samples.petclinic.owner.Pet) PetType(org.springframework.samples.petclinic.owner.PetType) Before(org.junit.Before)

Example 4 with PetType

use of org.springframework.samples.petclinic.owner.PetType in project spring-petclinic by spring-projects.

the class PetTypeFormatterTests method testPrint.

@Test
public void testPrint() {
    PetType petType = new PetType();
    petType.setName("Hamster");
    String petTypeName = this.petTypeFormatter.print(petType, Locale.ENGLISH);
    assertEquals("Hamster", petTypeName);
}
Also used : PetType(org.springframework.samples.petclinic.owner.PetType) Test(org.junit.Test)

Example 5 with PetType

use of org.springframework.samples.petclinic.owner.PetType in project spring-petclinic by spring-projects.

the class ClinicServiceTests method shouldFindAllPetTypes.

@Test
public void shouldFindAllPetTypes() {
    Collection<PetType> petTypes = this.pets.findPetTypes();
    PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
    assertThat(petType1.getName()).isEqualTo("cat");
    PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4);
    assertThat(petType4.getName()).isEqualTo("snake");
}
Also used : PetType(org.springframework.samples.petclinic.owner.PetType) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Aggregations

PetType (org.springframework.samples.petclinic.owner.PetType)6 Test (org.junit.Test)4 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)2 Owner (org.springframework.samples.petclinic.owner.Owner)2 Pet (org.springframework.samples.petclinic.owner.Pet)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Before (org.junit.Before)1 Transactional (org.springframework.transaction.annotation.Transactional)1