Skip to content

Commit

Permalink
Reorganize test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
zxh0 committed Oct 15, 2019
1 parent a8635ce commit 8748d5b
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 40 deletions.
4 changes: 2 additions & 2 deletions test/testclasses/src/main/java/UnitTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import helper.UnitTestRunner;
import jvm8.InterfaceMethodTest;
import jvm.lambda.InterfaceMethodTest;

public class UnitTests {

Expand Down Expand Up @@ -29,7 +29,7 @@ public static void main(String[] args) {
stdlib.basic.thread.MainThreadTest.class,
stdlib.basic.thread.SleepTest.class,
stdlib.basic.wrapper.DoubleTest.class,
//jvm8.InterfaceDefaultMethodTest.class,
//jvm.lambda.InterfaceDefaultMethodTest.class,
InterfaceMethodTest.class,
jls8.ch12.Eg12_4_1_1.class,
jls8.ch12.Eg12_4_1_2.class,
Expand Down
11 changes: 11 additions & 0 deletions test/testclasses/src/main/java/helper/MyAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package helper;

public class MyAssert {

public static void assertEquals(Object expected, Object actual) {
if (!expected.equals(actual)) {
throw new AssertionError(actual.toString() + " != " + expected.toString());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package stdlib.basic;
package jvm;

public class MethodCall {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package stdlib.basic;
package jvm;


public class ObjectInit {
Expand Down
32 changes: 32 additions & 0 deletions test/testclasses/src/main/java/jvm/jsr292/LookupTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package jvm.jsr292;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import static helper.MyAssert.assertEquals;

public class LookupTest {

public LookupTest(String[] x) {}
private void foo(String[] x) {}
public void bar(String[] x) {}
public int f1;
public static long f2;

public static void main(String[] args) throws Exception {
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodType mt = MethodType.methodType(void.class, String[].class);

assertEquals("MethodHandle(String[])void", lookup.findStatic(LookupTest.class, "main", mt).toString());
assertEquals("MethodHandle(String[])LookupTest", lookup.findConstructor(LookupTest.class, mt).toString());
assertEquals("MethodHandle(LookupTest,String[])void", lookup.findSpecial(LookupTest.class, "foo", mt, LookupTest.class).toString());
assertEquals("MethodHandle(LookupTest,String[])void", lookup.findVirtual(LookupTest.class, "bar", mt).toString());
assertEquals("MethodHandle(LookupTest)int", lookup.findGetter(LookupTest.class, "f1", int.class).toString());
assertEquals("MethodHandle(LookupTest,int)void", lookup.findSetter(LookupTest.class, "f1", int.class).toString());
assertEquals("MethodHandle()long", lookup.findStaticGetter(LookupTest.class, "f2", long.class).toString());
assertEquals("MethodHandle(long)void", lookup.findStaticSetter(LookupTest.class, "f2", long.class).toString());

System.out.println("OK!");
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jvm7.jsr292;
package jvm.jsr292;

import helper.ReflectionHelper;
import helper.UnitTestRunner;
Expand Down
33 changes: 33 additions & 0 deletions test/testclasses/src/main/java/jvm/jsr292/MethodHandleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package jvm.jsr292;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import static helper.MyAssert.assertEquals;

public class MethodHandleTest {

private static int x;

public static String test() {
return "hi";
}

public static void main(String[] args) throws Throwable {
MethodHandles.Lookup lookup = MethodHandles.lookup();

MethodType mt = MethodType.methodType(String.class);
MethodHandle mh = lookup.findStatic(MethodHandleTest.class, "test", mt);
assertEquals("hi", mh.invoke());
assertEquals("hi", (String) mh.invokeExact());

MethodHandle getter = lookup.findStaticGetter(MethodHandleTest.class, "x", int.class);
MethodHandle setter = lookup.findStaticSetter(MethodHandleTest.class, "x", int.class);
setter.invoke(100);
assertEquals(100, getter.invoke());

System.out.println("OK!");
}

}
20 changes: 20 additions & 0 deletions test/testclasses/src/main/java/jvm/jsr292/MethodTypeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package jvm.jsr292;

import java.util.Arrays;

import static java.lang.invoke.MethodType.*;
import static helper.MyAssert.assertEquals;

public class MethodTypeTest {

public static void main(String[] args) {
assertEquals("()void", methodType(void.class).toString()); // methodType(Class<?> rtype)
assertEquals("(String)Object", methodType(Object.class, String.class).toString()); // methodType(Class<?> rtype, Class<?> ptype0)
assertEquals("(int,long)String", methodType(String.class, int.class, long.class).toString()); // methodType(Class<?> rtype, Class<?> ptype0, Class<?>... ptypes)
assertEquals("(int)String", methodType(String.class, new Class<?>[]{int.class}).toString()); // methodType(Class<?> rtype, Class<?>[] ptypes)
assertEquals("(int)String", methodType(String.class, Arrays.asList(int.class)).toString()); // methodType(Class<?> rtype, List<Class<?>> ptypes)
assertEquals("()void", fromMethodDescriptorString("()V", null).toString());
System.out.println("OK!");
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jvm8;
package jvm.lambda;

import junit.framework.Assert;
import helper.UnitTestRunner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jvm8;
package jvm.lambda;

import helper.UnitTestRunner;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jvm8;
package jvm.lambda;

public class LambdaTest {

Expand Down
19 changes: 0 additions & 19 deletions test/testclasses/src/main/java/jvm7/jsr292/MethodHandleTest.java

This file was deleted.

13 changes: 0 additions & 13 deletions test/testclasses/src/main/java/jvm7/jsr292/MethodTypeTest.java

This file was deleted.

0 comments on commit 8748d5b

Please sign in to comment.