Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n9Mtq4 committed Jan 29, 2016
1 parent 5f38aae commit e06e7b5
Show file tree
Hide file tree
Showing 8 changed files with 1,028 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repositories {
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
}

gradle.taskGraph.afterTask { Task task, TaskState state ->
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/n9mtq4/reflection/ReflectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* Class to simplify reflection calls.<br>
*/
@SuppressWarnings("unused")
public class ReflectionHelper {
public final class ReflectionHelper {

/**
* Gets the instance of Unsafe.
Expand Down Expand Up @@ -2660,7 +2660,8 @@ public static boolean canBePrimitive(Class clazz) {
* @see ReflectionHelper#canBePrimitive(Class)
* */
public static boolean isPrimitive(Class clazz) {
return getObjectClass(clazz) != null;
return clazz.isPrimitive();
// return getObjectClass(clazz) != null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @author Will "n9Mtq4" Bresnahan
*/
@SuppressWarnings("unused")
public class ReflectionProtector {
public final class ReflectionProtector {

private static final int DEFAULT_INDEX = 3;

Expand Down
61 changes: 61 additions & 0 deletions src/test/java/com/n9mtq4/reflection/EnhancedProxyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.n9mtq4.reflection;

import com.n9mtq4.reflection.toreflect.TestInterface;
import com.n9mtq4.reflection.toreflect.TestInterfaceImplementation;
import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Method;

import static org.junit.Assert.*;

/**
* Created by will on 1/28/16 at 8:24 PM.
*
* @author Will "n9Mtq4" Bresnahan
*/
public class EnhancedProxyTest {

private int methodCalls = 0;

private TestInterfaceImplementation testInterfaceImplementation = new TestInterfaceImplementation();
private TestInterface ti;

@Before
public void setUp() throws Exception {

testInterfaceImplementation = new TestInterfaceImplementation();
ti = EnhancedProxy.newInstance(testInterfaceImplementation, new EnhancedProxy.EnhancedInvocationHandler() {
@Override
public Object invoke(Object obj, Object proxy, Method method, Object[] args) throws Throwable {

// does the same thing, but increments methodCalls by one
methodCalls++;
return EnhancedProxy.callChild(obj, method, args);

}
});

}

@Test
public void testEnhancedProxy() throws Exception {

System.out.println("Testing Enhanced Proxy");
assertTrue(methodCalls == 0);
ti.voidMethod();
assertTrue(methodCalls == 1);
assertTrue(ti.booleanMethod());
assertTrue(methodCalls == 2);
assertTrue(ti.charMethod() == 'a');
assertTrue(methodCalls == 3);
assertTrue(ti.stringMethod().equals("Hello World"));
assertTrue(methodCalls == 4);
assertTrue(ti.intMethod() == 1);
assertTrue(methodCalls == 5);
assertTrue(ti.doubleMethod() == 1.1);
assertTrue(methodCalls == 6);

}

}
Loading

0 comments on commit e06e7b5

Please sign in to comment.