Skip to content

Commit 54e3af2

Browse files
committed
Migrated to TestNG
1 parent 8ca8b1f commit 54e3af2

28 files changed

Lines changed: 429 additions & 146 deletions

‎pom.xml‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,15 @@
127127
<version>[1.6.4,)</version>
128128
</dependency>
129129
<dependency>
130-
<groupId>junit</groupId>
131-
<artifactId>junit</artifactId>
132-
<version>4.9</version>
130+
<groupId>org.testng</groupId>
131+
<artifactId>testng</artifactId>
132+
<version>6.3.1</version>
133+
<scope>test</scope>
134+
</dependency>
135+
<dependency>
136+
<groupId>org.hamcrest</groupId>
137+
<artifactId>hamcrest-all</artifactId>
138+
<version>1.3</version>
133139
<scope>test</scope>
134140
</dependency>
135141
<dependency>

‎src/main/java/de/danielbechler/diff/Instances.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public <T> T getFresh(final Class<T> type)
109109

110110
public boolean hasBeenAdded()
111111
{
112+
if (arePrimitive())
113+
{
114+
return false;
115+
}
112116
if (working != null && base == null)
113117
{
114118
return true;
@@ -122,6 +126,10 @@ public boolean hasBeenAdded()
122126

123127
public boolean hasBeenRemoved()
124128
{
129+
if (arePrimitive())
130+
{
131+
return false;
132+
}
125133
if (base != null && working == null)
126134
{
127135
return true;
@@ -133,6 +141,16 @@ public boolean hasBeenRemoved()
133141
return false;
134142
}
135143

144+
public boolean arePrimitive()
145+
{
146+
final Class<?> type = getType();
147+
if (type != null && type.isPrimitive() || Classes.isWrapperType(type))
148+
{
149+
return true;
150+
}
151+
return false;
152+
}
153+
136154
public boolean areEqual()
137155
{
138156
return Objects.isEqual(base, working);

‎src/main/java/de/danielbechler/util/Classes.java‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,35 @@ public final class Classes
2626
{
2727
private static final Logger logger = LoggerFactory.getLogger(Classes.class);
2828

29+
private static final Set<Class<?>> WRAPPER_TYPES = getWrapperTypes();
30+
2931
private Classes()
3032
{
3133
}
3234

35+
private static Set<Class<?>> getWrapperTypes()
36+
{
37+
final Set<Class<?>> wrapperTypes = new HashSet<Class<?>>();
38+
wrapperTypes.add(Boolean.class);
39+
wrapperTypes.add(Character.class);
40+
wrapperTypes.add(Byte.class);
41+
wrapperTypes.add(Short.class);
42+
wrapperTypes.add(Integer.class);
43+
wrapperTypes.add(Long.class);
44+
wrapperTypes.add(Float.class);
45+
wrapperTypes.add(Double.class);
46+
wrapperTypes.add(Void.class);
47+
return wrapperTypes;
48+
}
49+
50+
public static boolean isWrapperType(final Class<?> clazz)
51+
{
52+
return WRAPPER_TYPES.contains(clazz);
53+
}
54+
3355
public static boolean isSimpleType(final Class<?> clazz)
3456
{
35-
return clazz.isPrimitive() ||
36-
clazz.equals(Boolean.class) || clazz.equals(boolean.class) ||
37-
clazz.equals(Byte.class) || clazz.equals(byte.class) ||
38-
clazz.equals(Character.class) || clazz.equals(char.class) ||
39-
clazz.equals(Double.class) || clazz.equals(double.class) ||
40-
clazz.equals(Float.class) || clazz.equals(float.class) ||
41-
clazz.equals(Integer.class) || clazz.equals(int.class) ||
42-
clazz.equals(Long.class) || clazz.equals(long.class) ||
43-
clazz.equals(Short.class) || clazz.equals(short.class) ||
44-
clazz.isEnum() ||
57+
return clazz.isPrimitive() || isWrapperType(clazz) || clazz.isEnum() ||
4558
CharSequence.class.isAssignableFrom(clazz) ||
4659
Number.class.isAssignableFrom(clazz) ||
4760
Date.class.isAssignableFrom(clazz) ||
@@ -94,4 +107,5 @@ public static boolean allAssignableFrom(final Class<?> sharedType,
94107
}
95108
return matching;
96109
}
110+
97111
}

‎src/test/java/de/danielbechler/diff/BeanDifferTest.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
import de.danielbechler.diff.node.*;
2424
import de.danielbechler.diff.visitor.*;
2525
import org.hamcrest.core.*;
26-
import org.junit.*;
2726
import org.mockito.*;
27+
import org.testng.annotations.*;
2828

2929
import java.util.*;
3030

3131
import static de.danielbechler.diff.node.NodeAssertions.assertThat;
32+
import static org.hamcrest.MatcherAssert.assertThat;
3233
import static org.hamcrest.core.Is.*;
3334
import static org.hamcrest.core.IsSame.*;
34-
import static org.junit.Assert.assertThat;
3535
import static org.mockito.Mockito.*;
3636

3737
/** @author Daniel Bechler */
@@ -47,7 +47,7 @@ public class BeanDifferTest
4747
private Node node;
4848
private BeanDiffer differ;
4949

50-
@Before
50+
@BeforeMethod
5151
public void setUp()
5252
{
5353
MockitoAnnotations.initMocks(this);
@@ -66,13 +66,13 @@ public void testCompareWithDifferentStrings() throws Exception
6666
assertThat(node.getState(), is(Node.State.CHANGED));
6767
}
6868

69-
@Test(expected = IllegalArgumentException.class)
69+
@Test(expectedExceptions = IllegalArgumentException.class)
7070
public void testCompareWithDifferentTypes()
7171
{
7272
differ.compare("foo", 1337);
7373
}
7474

75-
@Test(expected = IllegalArgumentException.class)
75+
@Test(expectedExceptions = IllegalArgumentException.class)
7676
public void testCompareWithoutWorkingInstance()
7777
{
7878
when(delegate.isEqualsOnly(any(Node.class))).thenReturn(true);
@@ -172,7 +172,7 @@ public void testStupidStuffToGetOneHundredPercentCodeCoverage1()
172172
assertThat(differ.getConfiguration(), sameInstance(configuration));
173173
}
174174

175-
@Test(expected = IllegalArgumentException.class)
175+
@Test(expectedExceptions = IllegalArgumentException.class)
176176
public void testConstructionWithoutObjectDiffer()
177177
{
178178
new BeanDiffer(null);
@@ -191,8 +191,8 @@ public void testThatIgnoredPropertiesAreNeverAccessed()
191191
final ObjectWithAccessTrackingIgnoredProperty working = new ObjectWithAccessTrackingIgnoredProperty();
192192
final ObjectWithAccessTrackingIgnoredProperty base = new ObjectWithAccessTrackingIgnoredProperty();
193193
new BeanDiffer().compare(working, base);
194-
Assert.assertThat(working.accessed, Is.is(false));
195-
Assert.assertThat(base.accessed, Is.is(false));
194+
assertThat(working.accessed, Is.is(false));
195+
assertThat(base.accessed, Is.is(false));
196196
}
197197

198198
@Test

‎src/test/java/de/danielbechler/diff/CircularReferenceDetectorTest.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616

1717
package de.danielbechler.diff;
1818

19-
import org.junit.*;
19+
import org.testng.annotations.*;
2020

21+
import static org.hamcrest.MatcherAssert.*;
2122
import static org.hamcrest.core.Is.*;
22-
import static org.junit.Assert.*;
23+
import static org.testng.Assert.*;
2324

2425
/** @author Daniel Bechler */
2526
public class CircularReferenceDetectorTest
2627
{
2728
private CircularReferenceDetector circularReferenceDetector;
2829

29-
@Before
30+
@BeforeMethod
3031
public void setUp()
3132
{
3233
circularReferenceDetector = new CircularReferenceDetector();
@@ -67,7 +68,7 @@ public void testPush_adds_unknown_object_to_stack() throws Exception
6768
assertThat(circularReferenceDetector.size(), is(1));
6869
}
6970

70-
@Test(expected = CircularReferenceDetector.CircularReferenceException.class)
71+
@Test(expectedExceptions = CircularReferenceDetector.CircularReferenceException.class)
7172
public void testPush_throws_CircularReferenceException_on_known_object() throws Exception
7273
{
7374
circularReferenceDetector.push("foo");
@@ -82,7 +83,7 @@ public void testRemove_does_nothing_with_null_object() throws Exception
8283
assertThat(circularReferenceDetector.size(), is(0));
8384
}
8485

85-
@Test(expected = IllegalArgumentException.class)
86+
@Test(expectedExceptions = IllegalArgumentException.class)
8687
public void testRemove_throws_IllegalArgumentException_when_trying_to_remove_any_instance_other_than_the_last_pushed_one() throws Exception
8788
{
8889
circularReferenceDetector.push("foo");

‎src/test/java/de/danielbechler/diff/CollectionDifferTest.java‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,28 @@
2020
import de.danielbechler.diff.node.*;
2121
import de.danielbechler.diff.path.*;
2222
import de.danielbechler.diff.visitor.*;
23-
import org.junit.*;
23+
import org.testng.annotations.*;
2424

2525
import java.util.*;
2626

2727
import static de.danielbechler.diff.node.NodeAssertions.assertThat;
2828
import static de.danielbechler.diff.path.PropertyPath.*;
2929
import static java.util.Arrays.*;
30+
import static org.hamcrest.MatcherAssert.assertThat;
3031
import static org.hamcrest.core.Is.*;
31-
import static org.junit.Assert.assertThat;
3232

3333
/** @author Daniel Bechler */
3434
public class CollectionDifferTest
3535
{
3636
private CollectionDiffer differ;
3737

38-
@Before
38+
@BeforeMethod
3939
public void setUp() throws Exception
4040
{
4141
differ = new CollectionDiffer();
4242
}
4343

44-
@Test(expected = IllegalArgumentException.class)
44+
@Test(expectedExceptions = IllegalArgumentException.class)
4545
public void testConstructionWithoutDelegate()
4646
{
4747
new CollectionDiffer(null);
@@ -141,8 +141,7 @@ public void testCompareWithDifferentCollectionImplementationsSucceeds() throws E
141141
assertThat(node.hasChanges(), is(true));
142142
}
143143

144-
@Test
145-
@Ignore("Currently this is simply not possible because of the way, the CollectionItemAccessor works. Would be great, to support this.")
144+
@Test(enabled = false, description = "Currently this is simply not possible because of the way, the CollectionItemAccessor works. Would be great, to support this.")
146145
public void testCompareWithListContainingObjectTwiceDetectsIfOneGetsRemoved() throws Exception
147146
{
148147
final List<ObjectWithHashCodeAndEquals> base = asList(new ObjectWithHashCodeAndEquals("foo"), new ObjectWithHashCodeAndEquals("foo"));
@@ -157,8 +156,7 @@ public void testCompareWithListContainingObjectTwiceDetectsIfOneGetsRemoved() th
157156
.hasState(Node.State.REMOVED);
158157
}
159158

160-
@Test
161-
@Ignore("Currently this is simply not possible because of the way, the CollectionItemAccessor works. Would be great, to support this.")
159+
@Test(enabled = false, description = "Currently this is simply not possible because of the way, the CollectionItemAccessor works. Would be great, to support this.")
162160
public void testCompareWithListContainingObjectOnceDetectsIfAnotherInstanceOfItGetsAdded() throws Exception
163161
{
164162
final List<ObjectWithHashCodeAndEquals> base = asList(new ObjectWithHashCodeAndEquals("foo"));

‎src/test/java/de/danielbechler/diff/ConfigurationTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import de.danielbechler.diff.mock.*;
2020
import de.danielbechler.diff.node.*;
2121
import de.danielbechler.diff.path.*;
22-
import org.junit.*;
2322
import org.mockito.*;
2423
import org.mockito.invocation.*;
2524
import org.mockito.stubbing.*;
25+
import org.testng.annotations.*;
2626

2727
import static org.fest.assertions.api.Assertions.assertThat;
28+
import static org.hamcrest.MatcherAssert.assertThat;
2829
import static org.hamcrest.core.Is.*;
29-
import static org.junit.Assert.assertThat;
3030
import static org.mockito.Mockito.*;
3131

3232
/** @author Daniel Bechler */
@@ -37,7 +37,7 @@ public class ConfigurationTest
3737

3838
private Configuration configuration;
3939

40-
@Before
40+
@BeforeMethod
4141
public void setUp()
4242
{
4343
MockitoAnnotations.initMocks(this);

‎src/test/java/de/danielbechler/diff/DelegatingObjectDifferTest.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import de.danielbechler.diff.path.*;
2323
import de.danielbechler.diff.visitor.*;
2424
import org.hamcrest.core.*;
25-
import org.junit.*;
2625
import org.mockito.*;
26+
import org.testng.annotations.*;
2727

2828
import java.util.*;
2929

30-
import static org.junit.Assert.*;
30+
import static org.hamcrest.MatcherAssert.*;
3131
import static org.mockito.Mockito.*;
3232

3333
/** @author Daniel Bechler */
@@ -46,7 +46,7 @@ public class DelegatingObjectDifferTest
4646

4747
private DelegatingObjectDifferImpl differ;
4848

49-
@Before
49+
@BeforeMethod
5050
public void setUp() throws Exception
5151
{
5252
MockitoAnnotations.initMocks(this);
@@ -120,8 +120,8 @@ public void testCompareWithIgnoredMapProperty()
120120
final ObjectWithIgnoredMap base = new ObjectWithIgnoredMap();
121121
final ObjectDiffer objectDiffer = new DelegatingObjectDifferImpl();
122122
final Node node = objectDiffer.compare(working, base);
123-
Assert.assertThat(node.hasChanges(), Is.is(false));
124-
Assert.assertThat(node.hasChildren(), Is.is(false));
123+
assertThat(node.hasChanges(), Is.is(false));
124+
assertThat(node.hasChildren(), Is.is(false));
125125
}
126126

127127
@Test
@@ -134,7 +134,7 @@ public void testCompareWithIgnoredCollectionProperty()
134134
objectDiffer.getConfiguration().withoutProperty(PropertyPath.buildWith("collection"));
135135
final Node node = objectDiffer.compare(working, base);
136136
node.visit(new PrintingVisitor(working, base));
137-
Assert.assertThat(node.hasChanges(), Is.is(false));
138-
Assert.assertThat(node.hasChildren(), Is.is(false));
137+
assertThat(node.hasChanges(), Is.is(false));
138+
assertThat(node.hasChildren(), Is.is(false));
139139
}
140140
}

‎src/test/java/de/danielbechler/diff/InstancesTest.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package de.danielbechler.diff;
1818

1919
import de.danielbechler.diff.accessor.*;
20-
import org.junit.*;
20+
import org.testng.annotations.*;
2121

2222
import java.util.*;
2323

@@ -26,7 +26,7 @@
2626
/** @author Daniel Bechler */
2727
public class InstancesTest
2828
{
29-
@Test(expected = IllegalStateException.class)
29+
@Test(expectedExceptions = IllegalStateException.class)
3030
public void testGetType_throws_exception_for_incompatible_types() throws Exception
3131
{
3232
new Instances(RootAccessor.getInstance(), "foo", 1, null).getType();
@@ -68,4 +68,16 @@ public void testAreNull_returns_false_when_working_is_not_null()
6868
final Instances instances = new Instances(RootAccessor.getInstance(), "", null, null);
6969
assertThat(instances.areNull()).isFalse();
7070
}
71+
72+
@Test
73+
public void testArePrimitiveReturnsTrueForPrimitiveType()
74+
{
75+
assertThat(new Instances(RootAccessor.getInstance(), 1L, 2L, 0L).arePrimitive()).isTrue();
76+
}
77+
78+
@Test
79+
public void testArePrimitiveReturnsFalseForComplexType()
80+
{
81+
assertThat(new Instances(RootAccessor.getInstance(), "1", "2", null).arePrimitive()).isFalse();
82+
}
7183
}

0 commit comments

Comments
 (0)