Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
Add test to check no real constructor is called
Browse files Browse the repository at this point in the history
This test would fail without the changes from the previous commit.
  • Loading branch information
antlechner committed Dec 17, 2018
1 parent e6fb9d6 commit 6d2a9e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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();
}
}
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);
}
}

0 comments on commit 6d2a9e7

Please sign in to comment.