|
| 1 | +package com.baeldung.greeter.sample; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import java.time.LocalDateTime; |
| 6 | + |
| 7 | +import org.junit.Test; |
| 8 | +import org.junit.runner.RunWith; |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; |
| 10 | +import org.springframework.boot.test.context.SpringBootTest; |
| 11 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 12 | + |
| 13 | +import com.baeldung.greeter.Greeter; |
| 14 | + |
| 15 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 16 | +@SpringBootTest(classes = GreeterSampleApplication.class) |
| 17 | +public class GreeterSampleApplicationTest { |
| 18 | + |
| 19 | + @Autowired |
| 20 | + private Greeter greeter; |
| 21 | + |
| 22 | + @Test |
| 23 | + public void givenMorningTime_ifMorningMessage_thenSuccess() { |
| 24 | + String expected = "Hello Baeldung, Good Morning"; |
| 25 | + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 6, 0)); |
| 26 | + assertEquals(expected, actual); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void givenAfternoonTime_ifAfternoonMessage_thenSuccess() { |
| 31 | + String expected = "Hello Baeldung, Woha Afternoon"; |
| 32 | + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 13, 0)); |
| 33 | + assertEquals(expected, actual); |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + public void givenEveningTime_ifEveningMessage_thenSuccess() { |
| 38 | + String expected = "Hello Baeldung, Good Evening"; |
| 39 | + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 19, 0)); |
| 40 | + assertEquals(expected, actual); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void givenNightTime_ifNightMessage_thenSuccess() { |
| 45 | + String expected = "Hello Baeldung, Good Night"; |
| 46 | + String actual = greeter.greet(LocalDateTime.of(2017, 3, 1, 21, 0)); |
| 47 | + assertEquals(expected, actual); |
| 48 | + } |
| 49 | + |
| 50 | +} |
0 commit comments