Last active
April 16, 2019 23:09
-
-
Save singun/0130e2e00fb31343bae27e1d5304e55e to your computer and use it in GitHub Desktop.
Spring framework testing context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class HearingInterpreter { | |
private final WordProducer wordProducer; | |
HearingInterpreter(WordProducer wordProducer) { | |
this.wordProducer = wordProducer; | |
} | |
public String whatIHeard() { | |
String word = wordProducer.getWord(); | |
System.out.println(word); | |
return word; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HearingInterpreterTest { | |
HearingInterpreter hearingInterpreter; | |
@Before | |
public void setUp() { | |
hearingInterpreter = new HearingInterpreter(new LaurelWordProducer()); | |
} | |
@Test | |
public void whatIHeard() { | |
String word = hearingInterpreter.whatIHeard(); | |
assertThat(word).isEqualTo("Laurel"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@Primary | |
public class LaurelWordProducer implements WordProducer { | |
@Override | |
public String getWord() { | |
return "Laurel"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface WordProducer { | |
String getWord(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class YannyWordProducer implements WordProducer { | |
@Override | |
public String getWord() { | |
return "Yanny"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment