From 39fd847485d3d12273991b5fe5a51800025fbdc4 Mon Sep 17 00:00:00 2001 From: Michiel Van Huyck Date: Tue, 20 Sep 2022 21:14:27 +0200 Subject: [PATCH] #7.2 : assignment adding properties --- .../petclinic/sfg/PropertiesWordProducer.java | 2 +- src/main/resources/laurel.properties | 1 + .../sfg/junit5/PropertiesLaurelTest.java | 37 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/laurel.properties create mode 100644 src/test/java/org/springframework/samples/petclinic/sfg/junit5/PropertiesLaurelTest.java diff --git a/src/main/java/org/springframework/samples/petclinic/sfg/PropertiesWordProducer.java b/src/main/java/org/springframework/samples/petclinic/sfg/PropertiesWordProducer.java index e020246b..1ea95572 100644 --- a/src/main/java/org/springframework/samples/petclinic/sfg/PropertiesWordProducer.java +++ b/src/main/java/org/springframework/samples/petclinic/sfg/PropertiesWordProducer.java @@ -9,7 +9,7 @@ * Created by jt on 2019-02-18. */ @Component -@Profile("externalized") +@Profile({"externalized", "laurel-properties"}) @Primary public class PropertiesWordProducer implements WordProducer { diff --git a/src/main/resources/laurel.properties b/src/main/resources/laurel.properties new file mode 100644 index 00000000..a1b3e054 --- /dev/null +++ b/src/main/resources/laurel.properties @@ -0,0 +1 @@ +say.word=LAUrel \ No newline at end of file diff --git a/src/test/java/org/springframework/samples/petclinic/sfg/junit5/PropertiesLaurelTest.java b/src/test/java/org/springframework/samples/petclinic/sfg/junit5/PropertiesLaurelTest.java new file mode 100644 index 00000000..29dbbe8c --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/sfg/junit5/PropertiesLaurelTest.java @@ -0,0 +1,37 @@ +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.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Created by jt on 2019-02-18. + */ +@TestPropertySource("classpath:laurel.properties") +@ActiveProfiles("laurel-properties") +@SpringJUnitConfig(classes = PropertiesLaurelTest.TestConfig.class) +public class PropertiesLaurelTest { + + @Configuration + @ComponentScan("org.springframework.samples.petclinic.sfg") + static class TestConfig { + + } + + @Autowired + HearingInterpreter hearingInterpreter; + + @Test + void whatIheard() { + String word = hearingInterpreter.whatIheard(); + + assertEquals("LAUrel", word); + } +}