This repository has been archived by the owner on Jan 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to check no real constructor is called
This test would fail without the changes from the previous commit.
- Loading branch information
1 parent
e6fb9d6
commit 6d2a9e7
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/test/java/com/diffblue/deeptestutils/regression/ClassWithConstructor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.diffblue.deeptestutils.regression; | ||
|
||
public class ClassWithConstructor { | ||
|
||
public static Integer integerField; | ||
|
||
public int intField; | ||
|
||
public ClassWithConstructor() { | ||
intField = integerField.intValue(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/java/com/diffblue/deeptestutils/regression/ReflectorGetInstanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.diffblue.deeptestutils.regression; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import java.lang.reflect.InvocationTargetException; | ||
import com.diffblue.deeptestutils.Reflector; | ||
|
||
public class ReflectorGetInstanceTest { | ||
|
||
// This test checks that in a class with a constructor with no arguments, | ||
// calling Reflector.getInstance does not cause a call to that constructor. | ||
// If the constructor was called, a NullPointerException would happen as | ||
// integerField has its default value of null. | ||
@Test | ||
public void checkNoConstructorCall() throws InvocationTargetException { | ||
ClassWithConstructor cwc = (ClassWithConstructor) Reflector.getInstance | ||
("com.diffblue.deeptestutils.regression.ClassWithConstructor"); | ||
Assert.assertEquals(cwc.intField, 0); | ||
} | ||
} |