mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 05:15:50 +00:00
Updating using GitHub API 2025-06-19-15:31
This commit is contained in:
parent
c2256e1bb2
commit
33952e823a
1 changed files with 11 additions and 96 deletions
|
@ -1,97 +1,12 @@
|
||||||
/*
|
@Test
|
||||||
* Copyright 2012-2019 the original author or authors.
|
void shouldThrowParseException() {
|
||||||
*
|
given(this.pets.findPetTypes()).willReturn(makePetTypes());
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
Assertions.assertThrows(ParseException.class, () -> petTypeFormatter.parse("Fish", Locale.ENGLISH));
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://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.owner;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.BDDMockito.given;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.condition.DisabledInNativeImage;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for {@link PetTypeFormatter}
|
|
||||||
*
|
|
||||||
* @author Colin But
|
|
||||||
*/
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
@DisabledInNativeImage
|
|
||||||
class PetTypeFormatterTests {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private OwnerRepository pets;
|
|
||||||
|
|
||||||
private PetTypeFormatter petTypeFormatter;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setup() {
|
|
||||||
this.petTypeFormatter = new PetTypeFormatter(pets);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testPrint() {
|
|
||||||
PetType petType = new PetType();
|
|
||||||
petType.setName("Hamster");
|
|
||||||
String petTypeName = this.petTypeFormatter.print(petType, Locale.ENGLISH);
|
|
||||||
assertThat(petTypeName).isEqualTo("Hamster");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldParse() throws ParseException {
|
|
||||||
given(this.pets.findPetTypes()).willReturn(makePetTypes());
|
|
||||||
PetType petType = petTypeFormatter.parse("Bird", Locale.ENGLISH);
|
|
||||||
assertThat(petType.getName()).isEqualTo("Bird");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldThrowParseException() {
|
|
||||||
given(this.pets.findPetTypes()).willReturn(makePetTypes());
|
|
||||||
Assertions.assertThrows(ParseException.class, () -> {
|
|
||||||
petTypeFormatter.parse("Fish", Locale.ENGLISH);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<PetType> makePetTypes() {
|
||||||
|
List<PetType> petTypes = new ArrayList<>();
|
||||||
|
petTypes.add(new PetType("Dog"));
|
||||||
|
petTypes.add(new PetType("Bird"));
|
||||||
|
return petTypes;
|
||||||
|
}
|
Loading…
Reference in a new issue