mirror of
https://github.com/EsotericSoftware/reflectasm.git
synced 2025-03-23 07:40:16 +08:00
Skip tests that aren't supported in Java 17+. Make HasPublicConstructor constructor public. Rename/format/clean up. Eclipse encoding.
closes #89
This commit is contained in:
parent
783c59ad7c
commit
cad4d75511
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
@ -14,11 +14,21 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.reflectasm;
|
package com.esotericsoftware.reflectasm;
|
||||||
|
|
||||||
import static junit.framework.Assert.assertEquals;
|
import java.util.List;
|
||||||
import static junit.framework.Assert.assertTrue;
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
public class ConstructorAccessTest extends TestCase {
|
public class ConstructorAccessTest extends TestCase {
|
||||||
|
static private boolean java17;
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Object version = Runtime.class.getDeclaredMethod("version").invoke(null);
|
||||||
|
java17 = ((List<Integer>)version.getClass().getDeclaredMethod("version").invoke(version)).get(0) >= 17;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
java17 = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testNewInstance () {
|
public void testNewInstance () {
|
||||||
ConstructorAccess<SomeClass> access = ConstructorAccess.get(SomeClass.class);
|
ConstructorAccess<SomeClass> access = ConstructorAccess.get(SomeClass.class);
|
||||||
SomeClass someObject = new SomeClass();
|
SomeClass someObject = new SomeClass();
|
||||||
@ -28,6 +38,7 @@ public class ConstructorAccessTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPackagePrivateNewInstance () {
|
public void testPackagePrivateNewInstance () {
|
||||||
|
if (java17) return;
|
||||||
ConstructorAccess<PackagePrivateClass> access = ConstructorAccess.get(PackagePrivateClass.class);
|
ConstructorAccess<PackagePrivateClass> access = ConstructorAccess.get(PackagePrivateClass.class);
|
||||||
PackagePrivateClass someObject = new PackagePrivateClass();
|
PackagePrivateClass someObject = new PackagePrivateClass();
|
||||||
assertEquals(someObject, access.newInstance());
|
assertEquals(someObject, access.newInstance());
|
||||||
@ -39,12 +50,10 @@ public class ConstructorAccessTest extends TestCase {
|
|||||||
try {
|
try {
|
||||||
ConstructorAccess.get(HasArgumentConstructor.class);
|
ConstructorAccess.get(HasArgumentConstructor.class);
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
} catch (RuntimeException re) {
|
||||||
catch (RuntimeException re) {
|
|
||||||
System.out.println("Expected exception happened: " + re);
|
System.out.println("Expected exception happened: " + re);
|
||||||
}
|
} catch (Throwable t) {
|
||||||
catch (Throwable t) {
|
t.printStackTrace();
|
||||||
System.out.println("Unexpected exception happened: " + t);
|
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,36 +62,34 @@ public class ConstructorAccessTest extends TestCase {
|
|||||||
try {
|
try {
|
||||||
ConstructorAccess.get(HasPrivateConstructor.class);
|
ConstructorAccess.get(HasPrivateConstructor.class);
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
} catch (RuntimeException re) {
|
||||||
catch (RuntimeException re) {
|
|
||||||
System.out.println("Expected exception happened: " + re);
|
System.out.println("Expected exception happened: " + re);
|
||||||
}
|
} catch (Throwable t) {
|
||||||
catch (Throwable t) {
|
t.printStackTrace();
|
||||||
System.out.println("Unexpected exception happened: " + t);
|
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasProtectedConstructor () {
|
public void testHasProtectedConstructor () {
|
||||||
|
if (java17) return;
|
||||||
try {
|
try {
|
||||||
ConstructorAccess<HasProtectedConstructor> access = ConstructorAccess.get(HasProtectedConstructor.class);
|
ConstructorAccess<HasProtectedConstructor> access = ConstructorAccess.get(HasProtectedConstructor.class);
|
||||||
HasProtectedConstructor newInstance = access.newInstance();
|
HasProtectedConstructor newInstance = access.newInstance();
|
||||||
assertEquals("cow", newInstance.getMoo());
|
assertEquals("cow", newInstance.getMoo());
|
||||||
}
|
} catch (Throwable t) {
|
||||||
catch (Throwable t) {
|
t.printStackTrace();
|
||||||
System.out.println("Unexpected exception happened: " + t);
|
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHasPackageProtectedConstructor () {
|
public void testHasPackagePrivateConstructor () {
|
||||||
|
if (java17) return;
|
||||||
try {
|
try {
|
||||||
ConstructorAccess<HasPackageProtectedConstructor> access = ConstructorAccess.get(HasPackageProtectedConstructor.class);
|
ConstructorAccess<HasPackagePrivateConstructor> access = ConstructorAccess.get(HasPackagePrivateConstructor.class);
|
||||||
HasPackageProtectedConstructor newInstance = access.newInstance();
|
HasPackagePrivateConstructor newInstance = access.newInstance();
|
||||||
assertEquals("cow", newInstance.getMoo());
|
assertEquals("cow", newInstance.getMoo());
|
||||||
}
|
} catch (Throwable t) {
|
||||||
catch (Throwable t) {
|
t.printStackTrace();
|
||||||
System.out.println("Unexpected exception happened: " + t);
|
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,9 +99,8 @@ public class ConstructorAccessTest extends TestCase {
|
|||||||
ConstructorAccess<HasPublicConstructor> access = ConstructorAccess.get(HasPublicConstructor.class);
|
ConstructorAccess<HasPublicConstructor> access = ConstructorAccess.get(HasPublicConstructor.class);
|
||||||
HasPublicConstructor newInstance = access.newInstance();
|
HasPublicConstructor newInstance = access.newInstance();
|
||||||
assertEquals("cow", newInstance.getMoo());
|
assertEquals("cow", newInstance.getMoo());
|
||||||
}
|
} catch (Throwable t) {
|
||||||
catch (Throwable t) {
|
t.printStackTrace();
|
||||||
System.out.println("Unexpected exception happened: " + t);
|
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +158,7 @@ public class ConstructorAccessTest extends TestCase {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class HasArgumentConstructor {
|
static public class HasArgumentConstructor {
|
||||||
public String moo;
|
public String moo;
|
||||||
|
|
||||||
@ -170,8 +176,8 @@ public class ConstructorAccessTest extends TestCase {
|
|||||||
} else if (!moo.equals(other.moo)) return false;
|
} else if (!moo.equals(other.moo)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMoo() {
|
public String getMoo () {
|
||||||
return moo;
|
return moo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,14 +195,14 @@ public class ConstructorAccessTest extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class HasPackageProtectedConstructor extends HasProtectedConstructor {
|
static public class HasPackagePrivateConstructor extends HasProtectedConstructor {
|
||||||
HasPackageProtectedConstructor () {
|
HasPackagePrivateConstructor () {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class HasPublicConstructor extends HasPackageProtectedConstructor {
|
static public class HasPublicConstructor extends HasPackagePrivateConstructor {
|
||||||
HasPublicConstructor () {
|
public HasPublicConstructor () {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user