forked from itaifrenkel/java-hello-world-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloServiceTest.java
More file actions
40 lines (32 loc) · 1.05 KB
/
Copy pathHelloServiceTest.java
File metadata and controls
40 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Save this as: src/test/java/com/example/webapp/HelloServiceTest.java
package com.example.webapp;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
public class HelloServiceTest extends TestCase {
private HelloService service = new HelloService();
@Test
public void testGetMessage() {
assertEquals("Hello World!", service.getMessage());
}
@Test
public void testGreetWithName() {
assertEquals("Hello John!", service.greet("John"));
}
@Test
public void testGreetWithNull() {
assertEquals("Hello Guest!", service.greet(null));
}
@Test
public void testGreetWithEmptyString() {
assertEquals("Hello Guest!", service.greet(""));
}
@Test
public void testIsValidName() {
assertTrue(service.isValidName("John"));
assertFalse(service.isValidName(""));
assertFalse(service.isValidName("J"));
assertFalse(service.isValidName("John123"));
assertFalse(service.isValidName(null));
}
}