Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form parameter assn pierrot #8

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
</configuration>
</plugin>

<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.springframework.samples.petclinic.sfg;

import org.springframework.stereotype.Service;

/**
* Created by jt on 2019-02-16.
*/
@Service
public class HearingInterpreter {

private final WordProducer wordProducer;

public HearingInterpreter(WordProducer wordProducer) {
this.wordProducer = wordProducer;
}

public String whatIheard(){
String word = wordProducer.getWord();

System.out.println(word);

return word;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.springframework.samples.petclinic.sfg;

import org.springframework.stereotype.Component;

/**
* Created by jt on 2019-02-16.
*/
@Component
public class LaurelWordProducer implements WordProducer {
@Override
public String getWord() {
return "Laurel";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.springframework.samples.petclinic.sfg;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Created by jt on 2019-02-18.
*/
@Component
@Profile({"externalized", "laurel-properties"})
@Primary
public class PropertiesWordProducer implements WordProducer {

private String word;

@Value("${say.word}")
public void setWord(String word) {
this.word = word;
}

@Override
public String getWord() {
return word;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.springframework.samples.petclinic.sfg;

/**
* Created by jt on 2019-02-16.
*/
public interface WordProducer {

String getWord();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.springframework.samples.petclinic.sfg;

import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
* Created by jt on 2019-02-16.
*/
@Profile("yanny")
@Primary
@Component
public class YannyWordProducer implements WordProducer {
@Override
public String getWord() {
return "Yanny";
}
}
1 change: 1 addition & 0 deletions src/main/resources/laurel.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say.word=LAUrel
1 change: 1 addition & 0 deletions src/main/resources/yanny.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say.word=YaNNy
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.springframework.samples.petclinic.service;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.samples.petclinic.model.PetType;
import org.springframework.samples.petclinic.repository.OwnerRepository;
import org.springframework.samples.petclinic.repository.PetRepository;
import org.springframework.samples.petclinic.repository.VetRepository;
import org.springframework.samples.petclinic.repository.VisitRepository;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;

@ExtendWith(MockitoExtension.class)
class ClinicServiceImplTest {

@Mock
PetRepository petRepository;

@Mock
VetRepository vetRepository;

@Mock
OwnerRepository ownerRepository;

@Mock
VisitRepository visitRepository;

@InjectMocks
ClinicServiceImpl service;

@Test
void findPetTypes() {
//given
List<PetType> petTypeList = new ArrayList<>();
given(petRepository.findPetTypes()).willReturn(petTypeList);
//when
Collection<PetType> returnedPetTypes = service.findPetTypes();

//then
then(petRepository).should().findPetTypes();
assertThat(returnedPetTypes).isNotNull();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.springframework.samples.petclinic.sfg;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
* Created by jt on 2019-02-16.
*/
@Profile("base-test")
@Configuration
public class BaseConfig {

@Bean
HearingInterpreter hearingInterpreter(WordProducer wordProducer){
return new HearingInterpreter(wordProducer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.springframework.samples.petclinic.sfg;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import static org.junit.Assert.assertEquals;

@ActiveProfiles("base-test")
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {BaseConfig.class, LaurelConfig.class})
public class HearingInterpreterTest {

@Autowired
HearingInterpreter hearingInterpreter;

@Test
public void whatIheard() {
String word = hearingInterpreter.whatIheard();


assertEquals("Laurel", word);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.springframework.samples.petclinic.sfg;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import static org.junit.Assert.assertEquals;

@ActiveProfiles("base-test")
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {BaseConfig.class, YannyConfig.class})
public class HearingInterpreterYannyTest {

@Autowired
HearingInterpreter hearingInterpreter;

@Test
public void whatIheard() {
String word = hearingInterpreter.whatIheard();

assertEquals("Yanny", word);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.springframework.samples.petclinic.sfg;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
* Created by jt on 2019-02-16.
*/
@Profile("base-test")
@Configuration
public class LaurelConfig {

@Bean
LaurelWordProducer laurelWordProducer(){
return new LaurelWordProducer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.springframework.samples.petclinic.sfg;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

/**
* Created by jt on 2019-02-16.
*/
@Profile("base-test")
@Configuration
public class YannyConfig {

@Bean
YannyWordProducer yannyWordProducer(){
return new YannyWordProducer();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.springframework.samples.petclinic.sfg.junit5;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.samples.petclinic.sfg.HearingInterpreter;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Created by jt on 2019-02-18.
*/
@ActiveProfiles("yanny")
@SpringJUnitConfig(classes = HearingInterpreterActiveProfileTest.TestConfig.class)
public class HearingInterpreterActiveProfileTest {

@Configuration
@ComponentScan("org.springframework.samples.petclinic.sfg")
static class TestConfig {

}

@Autowired
HearingInterpreter hearingInterpreter;

@Test
void whatIheard() {
String word = hearingInterpreter.whatIheard();

assertEquals("Yanny", word);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.springframework.samples.petclinic.sfg.junit5;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.samples.petclinic.sfg.HearingInterpreter;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.junit.jupiter.api.Assertions.assertEquals;

@ActiveProfiles("component-scan")
@SpringJUnitConfig(classes = HearingInterpreterComponentScanTest.TestConfig.class)
class HearingInterpreterComponentScanTest {

@Profile("component-scan")
@Configuration
@ComponentScan("org.springframework.samples.petclinic.sfg")
static class TestConfig {

}

@Autowired
HearingInterpreter hearingInterpreter;

@Test
void whatIheard() {
String word = hearingInterpreter.whatIheard();

assertEquals("Laurel", word);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.springframework.samples.petclinic.sfg.junit5;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.samples.petclinic.sfg.HearingInterpreter;
import org.springframework.samples.petclinic.sfg.LaurelWordProducer;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

import static org.junit.jupiter.api.Assertions.assertEquals;

@ActiveProfiles("inner-class")
@SpringJUnitConfig(classes = HearingInterpreterInnerClassTest.TestConfig.class)
class HearingInterpreterInnerClassTest {

@Profile("inner-class")
@Configuration
static class TestConfig {

@Bean
HearingInterpreter hearingInterpreter(){
return new HearingInterpreter(new LaurelWordProducer());
}
}

@Autowired
HearingInterpreter hearingInterpreter;

@Test
void whatIheard() {
String word = hearingInterpreter.whatIheard();

assertEquals("Laurel", word);
}
}
Loading