Skip to content

Commit 5071230

Browse files
author
cristiii
committed
added couple of tests springframeworkguru#2
1 parent 1e20e47 commit 5071230

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

src/main/java/guru/springframework/sfgpetclinic/controllers/IndexController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public String index(){
88
}
99

1010
public String oupsHandler(){
11-
return "notimplemented";
11+
throw new ValueNotFoundException();
1212
}
1313
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package guru.springframework.sfgpetclinic.controllers;
2+
3+
public class ValueNotFoundException extends RuntimeException {
4+
}

src/test/java/guru/springframework/sfgpetclinic/controllers/IndexControllerTest.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package guru.springframework.sfgpetclinic.controllers;
22

33
import org.junit.jupiter.api.BeforeEach;
4+
import org.junit.jupiter.api.Disabled;
5+
import org.junit.jupiter.api.DisplayName;
46
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.api.condition.*;
8+
9+
import java.time.Duration;
510

611
import static org.junit.jupiter.api.Assertions.*;
12+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
713

814
class IndexControllerTest {
915

@@ -15,12 +21,62 @@ void setUp() {
1521
}
1622

1723
@Test
24+
@DisplayName("Test proper view name for index page")
1825
void index() {
1926
assertEquals("index", indexController.index());
2027
}
2128

2229
@Test
30+
@DisplayName("Test exception")
2331
void oupsHandler() {
24-
assertEquals("notimplemented", indexController.oupsHandler(), () -> "this is some expensive message to build for test");
32+
assertThrows(ValueNotFoundException.class, () -> {indexController.oupsHandler();});
33+
}
34+
35+
@Test
36+
@Disabled
37+
void testTimeOut() {
38+
assertTimeout(Duration.ofMillis(100), () -> {Thread.sleep(2000);
39+
System.out.println("I got here!");});
40+
}
41+
@Test
42+
@Disabled
43+
void testTimeOutPrempt() {
44+
assertTimeoutPreemptively(Duration.ofMillis(100), () -> {Thread.sleep(2000);
45+
System.out.println("I got here again!");});
46+
}
47+
48+
@Test
49+
void testAssumptionTrue() {
50+
assumeTrue("Cristi".equalsIgnoreCase(System.getenv("Cristi")));
51+
}
52+
53+
@Test
54+
@EnabledOnOs(OS.MAC)
55+
void testOnMacOs() {
56+
57+
}
58+
59+
@Test
60+
@EnabledOnOs(OS.WINDOWS)
61+
void testOnWindows() {
62+
63+
}
64+
65+
@Test
66+
@EnabledOnJre(JRE.JAVA_11)
67+
void testOnJava11() {
68+
69+
}
70+
71+
@Test
72+
@EnabledOnJre(JRE.OTHER)
73+
void testOnJava17() {
74+
75+
}
76+
77+
@Test
78+
@EnabledIfEnvironmentVariable(named = "USER", matches = "cristi")
79+
void testIfUser() {
80+
2581
}
2682
}

0 commit comments

Comments
 (0)