mirror of
https://github.com/EsotericSoftware/reflectasm.git
synced 2025-01-21 01:00:41 +08:00
Added regression tests
Added tests for all the expected cases of Constructor accesibility to ensure compatibility with Kryo unit tests.
This commit is contained in:
parent
b96de86918
commit
69b50c657e
@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.reflectasm;
|
package com.esotericsoftware.reflectasm;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertTrue;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
public class ConstructorAccessTest extends TestCase {
|
public class ConstructorAccessTest extends TestCase {
|
||||||
@ -20,6 +22,70 @@ public class ConstructorAccessTest extends TestCase {
|
|||||||
assertEquals(someObject, access.newInstance());
|
assertEquals(someObject, access.newInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testHasArgumentConstructor () {
|
||||||
|
try {
|
||||||
|
ConstructorAccess.get(HasArgumentConstructor.class);
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
catch (RuntimeException re) {
|
||||||
|
System.out.println("Expected exception happened: " + re);
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
System.out.println("Unexpected exception happened: " + t);
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testHasPrivateConstructor () {
|
||||||
|
try {
|
||||||
|
ConstructorAccess.get(HasPrivateConstructor.class);
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
catch (RuntimeException re) {
|
||||||
|
System.out.println("Expected exception happened: " + re);
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
System.out.println("Unexpected exception happened: " + t);
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testHasProtectedConstructor () {
|
||||||
|
try {
|
||||||
|
ConstructorAccess<HasProtectedConstructor> access = ConstructorAccess.get(HasProtectedConstructor.class);
|
||||||
|
HasProtectedConstructor newInstance = access.newInstance();
|
||||||
|
assertEquals("cow", newInstance.getMoo());
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
System.out.println("Unexpected exception happened: " + t);
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testHasPackageProtectedConstructor () {
|
||||||
|
try {
|
||||||
|
ConstructorAccess<HasPackageProtectedConstructor> access = ConstructorAccess.get(HasPackageProtectedConstructor.class);
|
||||||
|
HasPackageProtectedConstructor newInstance = access.newInstance();
|
||||||
|
assertEquals("cow", newInstance.getMoo());
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
System.out.println("Unexpected exception happened: " + t);
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testHasPublicConstructor () {
|
||||||
|
try {
|
||||||
|
ConstructorAccess<HasPublicConstructor> access = ConstructorAccess.get(HasPublicConstructor.class);
|
||||||
|
HasPublicConstructor newInstance = access.newInstance();
|
||||||
|
assertEquals("cow", newInstance.getMoo());
|
||||||
|
}
|
||||||
|
catch (Throwable t) {
|
||||||
|
System.out.println("Unexpected exception happened: " + t);
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class PackagePrivateClass {
|
static class PackagePrivateClass {
|
||||||
public String name;
|
public String name;
|
||||||
public int intValue;
|
public int intValue;
|
||||||
@ -73,4 +139,51 @@ public class ConstructorAccessTest extends TestCase {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public class HasArgumentConstructor {
|
||||||
|
public String moo;
|
||||||
|
|
||||||
|
public HasArgumentConstructor (String moo) {
|
||||||
|
this.moo = moo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals (Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null) return false;
|
||||||
|
if (getClass() != obj.getClass()) return false;
|
||||||
|
HasArgumentConstructor other = (HasArgumentConstructor)obj;
|
||||||
|
if (moo == null) {
|
||||||
|
if (other.moo != null) return false;
|
||||||
|
} else if (!moo.equals(other.moo)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMoo() {
|
||||||
|
return moo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static public class HasPrivateConstructor extends HasArgumentConstructor {
|
||||||
|
private HasPrivateConstructor () {
|
||||||
|
super("cow");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static public class HasProtectedConstructor extends HasPrivateConstructor {
|
||||||
|
protected HasProtectedConstructor () {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static public class HasPackageProtectedConstructor extends HasProtectedConstructor {
|
||||||
|
HasPackageProtectedConstructor () {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static public class HasPublicConstructor extends HasPackageProtectedConstructor {
|
||||||
|
HasPublicConstructor () {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user