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.
Merge pull request #59 from diffblue/antonia/objenesis-everywhere
Always use Objenesis to instantiate objects
- Loading branch information
Showing
3 changed files
with
39 additions
and
94 deletions.
There are no files selected for viewing
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
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); | ||
} | ||
} |