Skip to content

Commit 8db9a26

Browse files
committed
Merge pull request #9 from ppodgorsek/tests
Updated the tests.
2 parents f8c31b0 + 60dff12 commit 8db9a26

File tree

2 files changed

+104
-20
lines changed

2 files changed

+104
-20
lines changed

juncacher-core/src/test/java/com/github/ppodgorsek/juncacher/model/impl/IdentifiedInvalidationEntryTest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import org.junit.Test;
99

10-
import com.github.ppodgorsek.juncacher.model.InvalidationEntryType;
11-
1210
/**
1311
* Tests for the {@link IdentifiedInvalidationEntry} class.
1412
*
@@ -132,22 +130,4 @@ public void idGetterSetterWithNullValue() {
132130
identifiedInvalidationEntry.setId(null);
133131
}
134132

135-
@Test
136-
public void typeGetterSetterWithCorrectValue() {
137-
138-
final InvalidationEntryType newType = new ClassInvalidationEntryType(getClass());
139-
140-
identifiedInvalidationEntry.setType(newType);
141-
142-
final InvalidationEntryType type = identifiedInvalidationEntry.getType();
143-
144-
assertNotNull("The type shouldn't be null", type);
145-
assertEquals("Wrong type", newType, type);
146-
}
147-
148-
@Test(expected = IllegalArgumentException.class)
149-
public void typeGetterSetterWithNullValue() {
150-
identifiedInvalidationEntry.setType(null);
151-
}
152-
153133
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.github.ppodgorsek.juncacher.model.impl;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertNotNull;
6+
import static org.junit.Assert.assertTrue;
7+
8+
import org.junit.Test;
9+
10+
import com.github.ppodgorsek.juncacher.model.InvalidationEntryType;
11+
12+
/**
13+
* Tests for the {@link TypedInvalidationEntry} class.
14+
*
15+
* @author Paul Podgorsek
16+
*/
17+
public class TypedInvalidationEntryTest {
18+
19+
private final TypedInvalidationEntry typedInvalidationEntry = new TypedInvalidationEntry(
20+
DefaultInvalidationEntryType.GLOBAL);
21+
22+
@Test
23+
public void constructWithCorrectType() {
24+
new TypedInvalidationEntry(DefaultInvalidationEntryType.GLOBAL);
25+
}
26+
27+
@Test(expected = IllegalArgumentException.class)
28+
public void constructWithNullType() {
29+
new TypedInvalidationEntry(null);
30+
}
31+
32+
@Test
33+
public void equalsWithSameInstance() {
34+
assertTrue("The equals() method should return true",
35+
typedInvalidationEntry.equals(typedInvalidationEntry));
36+
}
37+
38+
@Test
39+
public void equalsWithDifferentClass() {
40+
assertFalse("The equals() method should return false",
41+
typedInvalidationEntry.equals(new Object()));
42+
}
43+
44+
@Test
45+
public void equalsWithDifferentInstanceHavingSameType() {
46+
47+
final TypedInvalidationEntry otherEntry = new TypedInvalidationEntry(
48+
DefaultInvalidationEntryType.GLOBAL);
49+
50+
assertTrue("The equals() method should return true",
51+
typedInvalidationEntry.equals(otherEntry));
52+
}
53+
54+
@Test
55+
public void equalsWithDifferentInstanceHavingDifferentType() {
56+
57+
final TypedInvalidationEntry otherEntry = new TypedInvalidationEntry(
58+
new ClassInvalidationEntryType(Object.class));
59+
60+
assertFalse("The equals() method should return false",
61+
typedInvalidationEntry.equals(otherEntry));
62+
}
63+
64+
@Test
65+
public void hashCodeWithCorrectValue() {
66+
67+
final int hashCode = typedInvalidationEntry.hashCode();
68+
69+
assertTrue("Wrong hashCode", hashCode != 0);
70+
}
71+
72+
@Test
73+
public void toStringWithCorrectValues() {
74+
75+
final StringBuilder sbld = new StringBuilder();
76+
sbld.append("TypedInvalidationEntry[type=");
77+
sbld.append(DefaultInvalidationEntryType.GLOBAL);
78+
sbld.append("]");
79+
80+
final String toStringValue = typedInvalidationEntry.toString();
81+
82+
assertNotNull("The toString() value shouldn't be null", toStringValue);
83+
assertEquals("Wrong toString() value", sbld.toString(), toStringValue);
84+
}
85+
86+
@Test
87+
public void typeGetterSetterWithCorrectValue() {
88+
89+
final InvalidationEntryType newType = new ClassInvalidationEntryType(getClass());
90+
91+
typedInvalidationEntry.setType(newType);
92+
93+
final InvalidationEntryType type = typedInvalidationEntry.getType();
94+
95+
assertNotNull("The type shouldn't be null", type);
96+
assertEquals("Wrong type", newType, type);
97+
}
98+
99+
@Test(expected = IllegalArgumentException.class)
100+
public void typeGetterSetterWithNullValue() {
101+
typedInvalidationEntry.setType(null);
102+
}
103+
104+
}

0 commit comments

Comments
 (0)