-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectAssertion.java
58 lines (50 loc) · 1.67 KB
/
ObjectAssertion.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
public class ObjectAssertion {
private Object o; //Private field.
//Constructor
public ObjectAssertion(Object o) {
this.o = o;
}
/*
Raise an exception (any exception) if o is null, otherwise return an object
such that more of the methods in this chain can be called.
*/
public ObjectAssertion isNotNull() {
if(o == null) {
throw new UnsupportedOperationException("ObjectAssertion.isNotNull() raises exception.");
} else {
return this;
}
}
//Raise exception if o is not null.
public ObjectAssertion isNull() {
if(o != null) {
throw new UnsupportedOperationException("ObjectAssertion.isNull() raises exception.");
} else {
return this;
}
}
//Raise exception if o is not .equals to o2.
public ObjectAssertion isEqualTo(Object o2) {
if(!o.equals(o2)) {
throw new UnsupportedOperationException("ObjectAssertion.isEqualTo(Object o2) raises exception.");
} else {
return this;
}
}
//Raise exception if o is .equals to o2.
public ObjectAssertion isNotEqualTo(Object o2) {
if(o.equals(o2)) {
throw new UnsupportedOperationException("ObjectAssertion.isNotEqualTo(Object o2) raises exception.");
} else {
return this;
}
}
//Raise exception if o is not an instance of Class c
public ObjectAssertion isInstanceOf(Class c) {
if(!c.isInstance(o)) {
throw new UnsupportedOperationException("ObjectAssertion.isInstanceOf(Class c) raises exception.");
} else {
return this;
}
}
}