-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringAssertion.java
76 lines (66 loc) · 2.23 KB
/
StringAssertion.java
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
public class StringAssertion {
private String s; //Private field.
//Constructor
public StringAssertion(String s) {
this.s = s;
}
/*
Raise an exception (any exception) if s is null, otherwise return an object
such that more of the methods in this chain can be called.
*/
public StringAssertion isNotNull() {
if(s == null) {
throw new UnsupportedOperationException("StringAssertion.isNotNull() raises exception.");
} else {
return this;
}
}
//Raise exception if s is not null.
public StringAssertion isNull() {
if(s != null) {
throw new UnsupportedOperationException("StringAssertion.isNull() raises exception.");
} else {
return this;
}
}
//Raise exception if s is not .equals to o.
public StringAssertion isEqualTo(Object o) {
if(!s.equals(o)) {
throw new UnsupportedOperationException("StringAssertion.isEqualTo(Object o) raises exception.");
} else {
return this;
}
}
//Raise exception if s is .equals to o.
public StringAssertion isNotEqualTo(Object o) {
if(s.equals(o)) {
throw new UnsupportedOperationException("StringAssertion.isNotEqualTo(Object o) raises exception.");
} else {
return this;
}
}
//Raises an exception if s does not start with s2.
public StringAssertion startsWith(String s2) {
if(!s.startsWith(s2)) {
throw new UnsupportedOperationException("StringAssertion.startsWith(String s2) raises exception.");
} else {
return this;
}
}
//Raises an exception if s is not the empty string.
public StringAssertion isEmpty() {
if(!s.isEmpty()) {
throw new UnsupportedOperationException("StringAssertion.isEmpty() raises exception.");
} else {
return this;
}
}
//Raises an exception if s does not contain s2.
public StringAssertion contains(String s2) {
if(!s.contains(s2)) {
throw new UnsupportedOperationException("StringAssertion.contains(String s2) raises exception.");
} else {
return this;
}
}
}