From 53500083ef1f5438d338ad80843a734962debf7a Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Thu, 4 May 2017 20:13:13 -0400 Subject: [PATCH 1/7] Finish first 3 methods --- .gitignore | 1 + .idea/.name | 1 + .idea/compiler.xml | 16 + .idea/libraries/Maven__junit_junit_4_12.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 + .idea/misc.xml | 19 + .idea/modules.xml | 8 + .idea/uiDesigner.xml | 124 +++ .idea/vcs.xml | 6 + .idea/workspace.xml | 879 ++++++++++++++++++ TypeInformation.iml | 17 + pom.xml | 25 + .../garcia/luis/typeinformation/Main.java | 33 + .../luis/typeinformation/TypeInformation.java | 79 ++ src/test/java/TestTypeInformation.java | 53 ++ 15 files changed, 1287 insertions(+) create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/libraries/Maven__junit_junit_4_12.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 TypeInformation.iml create mode 100644 pom.xml create mode 100644 src/main/java/garcia/luis/typeinformation/Main.java create mode 100644 src/main/java/garcia/luis/typeinformation/TypeInformation.java create mode 100644 src/test/java/TestTypeInformation.java diff --git a/.gitignore b/.gitignore index 32858aa..8fea83e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.jar *.war *.ear +.DS_Store # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..6668c41 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +typeinformation \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61bbb77 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..38d97d5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + false + + false + false + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1ee38f5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..31fea29 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,879 @@ + + + + + + + + + + + + garcia.luis.typeinformation.* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1493914264146 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + TypeInformation + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TypeInformation.iml b/TypeInformation.iml new file mode 100644 index 0000000..03320bd --- /dev/null +++ b/TypeInformation.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2ca5c5a --- /dev/null +++ b/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + garcia.luis + typeinformation + 1.0-SNAPSHOT + + + junit + junit + 4.12 + + + junit + junit + RELEASE + + + + + + \ No newline at end of file diff --git a/src/main/java/garcia/luis/typeinformation/Main.java b/src/main/java/garcia/luis/typeinformation/Main.java new file mode 100644 index 0000000..a0ef4af --- /dev/null +++ b/src/main/java/garcia/luis/typeinformation/Main.java @@ -0,0 +1,33 @@ +package garcia.luis.typeinformation; + +import garcia.luis.typeinformation.TypeInformation; +import sun.rmi.rmic.Constants; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.function.BiConsumer; +import java.util.function.IntConsumer; +import java.util.function.IntToDoubleFunction; + +/** + * Created by luisgarcia on 5/4/17. + */ +public class Main +{ + public static void main(String[] args) + { + TypeInformation myTest = new TypeInformation(); + String name = "Paco"; + Calendar date = Calendar.getInstance(); + double a = 1; + + Class cl = date.getClass(); + + myTest.listAllMembers(cl); + myTest.getClassHierarchy(cl); + + + + } +} diff --git a/src/main/java/garcia/luis/typeinformation/TypeInformation.java b/src/main/java/garcia/luis/typeinformation/TypeInformation.java new file mode 100644 index 0000000..9f05969 --- /dev/null +++ b/src/main/java/garcia/luis/typeinformation/TypeInformation.java @@ -0,0 +1,79 @@ +package garcia.luis.typeinformation; + +import org.junit.Test; +import org.junit.Assert; +import java.lang.reflect.*; +import java.util.ArrayList; + +/** + * Created by luisgarcia on 5/4/17. + */ +public class TypeInformation +{ + public TypeInformation(){} + + public boolean classImplementsInterface(Object obj, Class cl) + { + Class classObject = cl.getClass(); + if(classObject.isInstance(obj)) + { + return true; + } + else + { + return false; + } + } + + public void listAllMembers(Class obj) + { + Method[] methods = obj.getClass().getDeclaredMethods(); + obj.getClass().getClass(); + + System.out.println(obj.getClass().getDeclaredMethods().length); + for(int i = 0; i < methods.length; i++) + { + System.out.println(methods[i]); + } + + System.out.println("size = " + methods.length); + } + + public void getClassHierarchy(Class obj) + { + String tab =""; + System.out.println("Class Hierarchy"); + ArrayList mySuperList = getSuperClass(obj); + + for(int i = mySuperList.size()-1;i >= 0; i--) + { + System.out.println(tab + mySuperList.get(i)); + tab= tab + " "; + + } + + + + } + + public ArrayList getSuperClass(Class obj) + { + ArrayList superClassList = new ArrayList(); + String superClass = Object.class.getName(); + int i =0; + + + do{ + superClassList.add(obj.getSuperclass().getName()); + obj = obj.getSuperclass(); + + } + while (!superClass.equals(superClassList.get(i++))); + + return superClassList; + + } + + + +} diff --git a/src/test/java/TestTypeInformation.java b/src/test/java/TestTypeInformation.java new file mode 100644 index 0000000..99ff7c9 --- /dev/null +++ b/src/test/java/TestTypeInformation.java @@ -0,0 +1,53 @@ + +import garcia.luis.typeinformation.TypeInformation; +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Method; +import java.util.AbstractCollection; + +/** + * Created by luisgarcia on 5/4/17. + */ +public class TestTypeInformation +{ + TypeInformation test = new TypeInformation(); + String strObj = "hello"; + Double dbl = 3.2; + Class cl = dbl.getClass(); + + @Test + public void testImplementsInterface() + { + //given + boolean expected = false; + + //when + boolean actual = test.classImplementsInterface(strObj, cl); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void testListAllMembers() + { + //when + Method[] methods = strObj.getClass().getDeclaredMethods(); + int expected = 77; + + //when + int actual = strObj.getClass().getDeclaredMethods().length; + + //then + Assert.assertEquals(expected, actual, 0); + + } + + @Test + public void testHierarchy() + { + + } + +} From e12cfb0ea3c9aa9a40aa1ca9ca630637676d8a09 Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Thu, 4 May 2017 21:53:44 -0400 Subject: [PATCH 2/7] Working on instantiateClassHierarchy --- .idea/workspace.xml | 29 ++++---- .../garcia/luis/typeinformation/Main.java | 8 +-- .../luis/typeinformation/TypeInformation.java | 72 ++++++++++++++++--- 3 files changed, 81 insertions(+), 28 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 31fea29..02a97d1 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,8 @@ - + + @@ -27,11 +28,12 @@ - - + + - + + @@ -40,8 +42,8 @@ - - + + @@ -671,7 +673,7 @@ @@ -693,7 +695,7 @@ - @@ -781,8 +783,8 @@ - - + + @@ -791,11 +793,12 @@ - - + + - + + diff --git a/src/main/java/garcia/luis/typeinformation/Main.java b/src/main/java/garcia/luis/typeinformation/Main.java index a0ef4af..3c277b3 100644 --- a/src/main/java/garcia/luis/typeinformation/Main.java +++ b/src/main/java/garcia/luis/typeinformation/Main.java @@ -6,9 +6,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.function.BiConsumer; -import java.util.function.IntConsumer; -import java.util.function.IntToDoubleFunction; + /** * Created by luisgarcia on 5/4/17. @@ -18,16 +16,14 @@ public class Main public static void main(String[] args) { TypeInformation myTest = new TypeInformation(); - String name = "Paco"; Calendar date = Calendar.getInstance(); - double a = 1; Class cl = date.getClass(); myTest.listAllMembers(cl); myTest.getClassHierarchy(cl); - + System.out.println(myTest.instantiateClassHierarchy(cl)); } } diff --git a/src/main/java/garcia/luis/typeinformation/TypeInformation.java b/src/main/java/garcia/luis/typeinformation/TypeInformation.java index 9f05969..2c11f98 100644 --- a/src/main/java/garcia/luis/typeinformation/TypeInformation.java +++ b/src/main/java/garcia/luis/typeinformation/TypeInformation.java @@ -14,7 +14,7 @@ public TypeInformation(){} public boolean classImplementsInterface(Object obj, Class cl) { - Class classObject = cl.getClass(); + Class classObject = obj.getClass(); if(classObject.isInstance(obj)) { return true; @@ -25,18 +25,56 @@ public boolean classImplementsInterface(Object obj, Class cl) } } + public boolean classImplementsInterface(Class obj, Class cl) + { + + if(cl.isInstance(obj)) + { + return true; + } + else + { + return false; + } + } + + public boolean classImplementsInterface(String obj, Class cl) + { + Class classObject = obj.getClass(); + if(cl.isInstance(obj)) + { + return true; + } + else + { + return false; + } + } + public void listAllMembers(Class obj) { - Method[] methods = obj.getClass().getDeclaredMethods(); - obj.getClass().getClass(); + Class cl = obj.getClass(); + Constructor[] constructors = cl.getDeclaredConstructors(); + Field [] fields = cl.getDeclaredFields(); + Method [] methods = cl.getDeclaredMethods(); - System.out.println(obj.getClass().getDeclaredMethods().length); - for(int i = 0; i < methods.length; i++) - { - System.out.println(methods[i]); - } + System.out.println("Constructors"); + for(int i = 0; i < constructors.length; i++) + { + System.out.println(constructors[i]); + } + System.out.println("Fields"); + for(int i = 0; i < fields.length; i++) + { + System.out.println(fields[i]); + } + System.out.println("Methods"); + for(int i = 0; i < methods.length; i++) + { + System.out.println(methods[i]); + } + System.out.println(); - System.out.println("size = " + methods.length); } public void getClassHierarchy(Class obj) @@ -74,6 +112,22 @@ public ArrayList getSuperClass(Class obj) } + public ArrayList instantiateClassHierarchy(Class obj) + { + ArrayList myList = getSuperClass(obj); + ArrayList instance = new ArrayList(); + for(int i = 0; i < myList.size(); i++) + { + if(obj.getClass().isInstance(myList.get(i))) + { + instance.add(myList.get(i)); + } + } + return instance; + } + + + } From c68aa6d60e6ce052cb4bb65120d3f5f00b2c893a Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Thu, 4 May 2017 22:14:07 -0400 Subject: [PATCH 3/7] still working --- .idea/workspace.xml | 18 +++++++++--------- .../luis/typeinformation/TypeInformation.java | 11 ++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 02a97d1..c9d2e23 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,7 @@ - + @@ -28,8 +28,8 @@ - - + + @@ -673,7 +673,7 @@ @@ -695,10 +695,10 @@ - - + @@ -710,7 +710,7 @@ - + @@ -793,8 +793,8 @@ - - + + diff --git a/src/main/java/garcia/luis/typeinformation/TypeInformation.java b/src/main/java/garcia/luis/typeinformation/TypeInformation.java index 2c11f98..b074c6f 100644 --- a/src/main/java/garcia/luis/typeinformation/TypeInformation.java +++ b/src/main/java/garcia/luis/typeinformation/TypeInformation.java @@ -120,7 +120,16 @@ public ArrayList instantiateClassHierarchy(Class obj) { if(obj.getClass().isInstance(myList.get(i))) { - instance.add(myList.get(i)); + try { + Object m = Class.forName(obj.getName()).newInstance(); + instance.add(m); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } } } return instance; From 6fe4fa2d2381fd7ff7ebbd4413c5b3769a799439 Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Fri, 5 May 2017 13:44:58 -0400 Subject: [PATCH 4/7] working on unitcorn --- .idea/workspace.xml | 187 ++++++++++++------ .../TypeInformation.java | 9 +- .../garcia/luis/typeinformation/Main.java | 29 --- .../java/unitcorn/UnitCornTestRunner.java | 41 ++++ src/test/java/TestTypeInformation.java | 16 +- 5 files changed, 188 insertions(+), 94 deletions(-) rename src/main/java/garcia/luis/{typeinformation => }/TypeInformation.java (93%) delete mode 100644 src/main/java/garcia/luis/typeinformation/Main.java create mode 100644 src/main/java/unitcorn/UnitCornTestRunner.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c9d2e23..98a4611 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,9 @@ - - + + + @@ -25,27 +26,28 @@ - - + + - - + + - - + + - - + + - - + + + @@ -54,11 +56,9 @@ - - - - - + + + @@ -85,10 +85,12 @@ @@ -100,8 +102,8 @@ @@ -193,8 +195,34 @@ - + @@ -277,6 +305,27 @@ + + + + + + + + @@ -673,32 +724,47 @@ - - + + + + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + - - + @@ -710,14 +776,14 @@ - + - + - + @@ -741,7 +807,7 @@ - @@ -771,34 +837,41 @@ + + + + + + + + - - - - - + + + - + - - + + + + - + - - + + - - + diff --git a/src/main/java/garcia/luis/typeinformation/TypeInformation.java b/src/main/java/garcia/luis/TypeInformation.java similarity index 93% rename from src/main/java/garcia/luis/typeinformation/TypeInformation.java rename to src/main/java/garcia/luis/TypeInformation.java index b074c6f..b2394f7 100644 --- a/src/main/java/garcia/luis/typeinformation/TypeInformation.java +++ b/src/main/java/garcia/luis/TypeInformation.java @@ -1,7 +1,5 @@ -package garcia.luis.typeinformation; +package garcia.luis; -import org.junit.Test; -import org.junit.Assert; import java.lang.reflect.*; import java.util.ArrayList; @@ -10,12 +8,11 @@ */ public class TypeInformation { - public TypeInformation(){} public boolean classImplementsInterface(Object obj, Class cl) { Class classObject = obj.getClass(); - if(classObject.isInstance(obj)) + if(classObject.isInstance(cl)) { return true; } @@ -121,7 +118,7 @@ public ArrayList instantiateClassHierarchy(Class obj) if(obj.getClass().isInstance(myList.get(i))) { try { - Object m = Class.forName(obj.getName()).newInstance(); + Object m = Class.forName(obj.getClass().getName()).newInstance(); instance.add(m); } catch (InstantiationException e) { e.printStackTrace(); diff --git a/src/main/java/garcia/luis/typeinformation/Main.java b/src/main/java/garcia/luis/typeinformation/Main.java deleted file mode 100644 index 3c277b3..0000000 --- a/src/main/java/garcia/luis/typeinformation/Main.java +++ /dev/null @@ -1,29 +0,0 @@ -package garcia.luis.typeinformation; - -import garcia.luis.typeinformation.TypeInformation; -import sun.rmi.rmic.Constants; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; - - -/** - * Created by luisgarcia on 5/4/17. - */ -public class Main -{ - public static void main(String[] args) - { - TypeInformation myTest = new TypeInformation(); - Calendar date = Calendar.getInstance(); - - Class cl = date.getClass(); - - myTest.listAllMembers(cl); - myTest.getClassHierarchy(cl); - - System.out.println(myTest.instantiateClassHierarchy(cl)); - - } -} diff --git a/src/main/java/unitcorn/UnitCornTestRunner.java b/src/main/java/unitcorn/UnitCornTestRunner.java new file mode 100644 index 0000000..c1160c2 --- /dev/null +++ b/src/main/java/unitcorn/UnitCornTestRunner.java @@ -0,0 +1,41 @@ +package unitcorn; + +import org.junit.Test; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.ArrayList; + +/** + * Created by luisgarcia on 5/5/17. + */ +public class UnitCornTestRunner +{ + public void runTest(Class c, String methodName) + { + + } + + public void runTests(Class c) + { + ArrayList myAnnotationMethod = new ArrayList(); + Method[] methods = c.getDeclaredMethods(); + + while(c != Object.class) + { + for(int i = 0; i < methods.length; i++) + { + if(methods[i].isAnnotationPresent(Test.class)) + { + runTest(c, methods[i].getName() ); + } + } + + + } + + + + } + +} diff --git a/src/test/java/TestTypeInformation.java b/src/test/java/TestTypeInformation.java index 99ff7c9..3e857c7 100644 --- a/src/test/java/TestTypeInformation.java +++ b/src/test/java/TestTypeInformation.java @@ -1,10 +1,10 @@ -import garcia.luis.typeinformation.TypeInformation; +import garcia.luis.TypeInformation; import org.junit.Assert; import org.junit.Test; import java.lang.reflect.Method; -import java.util.AbstractCollection; +import java.util.ArrayList; /** * Created by luisgarcia on 5/4/17. @@ -15,6 +15,8 @@ public class TestTypeInformation String strObj = "hello"; Double dbl = 3.2; Class cl = dbl.getClass(); + ArrayList myList; + @Test public void testImplementsInterface() @@ -47,6 +49,16 @@ public void testListAllMembers() @Test public void testHierarchy() { + //given + myList = test.getSuperClass(cl); + String expected = "java.lang.Object"; + + //when + String actual = myList.get(1); + + //then + Assert.assertEquals(expected, actual); + } From 16ad7735d192f9ce934424f84080c2e68518abec Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Fri, 5 May 2017 16:53:15 -0400 Subject: [PATCH 5/7] finishhed part 2 runtests ; q gi git : --- .../Maven__com_beust_jcommander_1_64.xml | 13 + .../Maven__org_testng_testng_6_11.xml | 13 + .../Maven__org_yaml_snakeyaml_1_17.xml | 13 + .idea/workspace.xml | 227 ++++++++++++------ TypeInformation.iml | 3 + pom.xml | 5 + src/main/java/unitcorn/Result.java | 9 + .../java/unitcorn/UnitCornTestRunner.java | 46 +++- src/test/java/TestUnitCornTestRunner.java | 43 ++++ 9 files changed, 280 insertions(+), 92 deletions(-) create mode 100644 .idea/libraries/Maven__com_beust_jcommander_1_64.xml create mode 100644 .idea/libraries/Maven__org_testng_testng_6_11.xml create mode 100644 .idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml create mode 100644 src/main/java/unitcorn/Result.java create mode 100644 src/test/java/TestUnitCornTestRunner.java diff --git a/.idea/libraries/Maven__com_beust_jcommander_1_64.xml b/.idea/libraries/Maven__com_beust_jcommander_1_64.xml new file mode 100644 index 0000000..e72647c --- /dev/null +++ b/.idea/libraries/Maven__com_beust_jcommander_1_64.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_testng_testng_6_11.xml b/.idea/libraries/Maven__org_testng_testng_6_11.xml new file mode 100644 index 0000000..5105222 --- /dev/null +++ b/.idea/libraries/Maven__org_testng_testng_6_11.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml b/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml new file mode 100644 index 0000000..20e2920 --- /dev/null +++ b/.idea/libraries/Maven__org_yaml_snakeyaml_1_17.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 98a4611..c5b4845 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,10 @@ - - - + + + + @@ -29,8 +30,8 @@ - - + + @@ -43,22 +44,45 @@ - - + + - + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + @@ -90,6 +114,8 @@ @@ -242,28 +268,7 @@ - - - - - - - - - + @@ -284,14 +289,14 @@ - + - + + + + + + + + + + + + + + + @@ -724,44 +772,44 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - @@ -770,7 +818,7 @@ - + @@ -807,7 +855,7 @@ - @@ -847,16 +895,18 @@ - - - + + + + + - - + + @@ -865,13 +915,30 @@ - + + + + + + + + + + + - + + + + + + + + + - diff --git a/TypeInformation.iml b/TypeInformation.iml index 03320bd..3b72213 100644 --- a/TypeInformation.iml +++ b/TypeInformation.iml @@ -13,5 +13,8 @@ + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2ca5c5a..5fa5bb2 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,11 @@ junit RELEASE + + org.testng + testng + RELEASE + diff --git a/src/main/java/unitcorn/Result.java b/src/main/java/unitcorn/Result.java new file mode 100644 index 0000000..140341d --- /dev/null +++ b/src/main/java/unitcorn/Result.java @@ -0,0 +1,9 @@ +package unitcorn; + +/** + * Created by luisgarcia on 5/5/17. + */ +public class Result +{ + +} diff --git a/src/main/java/unitcorn/UnitCornTestRunner.java b/src/main/java/unitcorn/UnitCornTestRunner.java index c1160c2..50fdafa 100644 --- a/src/main/java/unitcorn/UnitCornTestRunner.java +++ b/src/main/java/unitcorn/UnitCornTestRunner.java @@ -1,11 +1,14 @@ package unitcorn; +import garcia.luis.TypeInformation; +import org.junit.Assert; import org.junit.Test; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.ArrayList; + /** * Created by luisgarcia on 5/5/17. */ @@ -13,28 +16,47 @@ public class UnitCornTestRunner { public void runTest(Class c, String methodName) { - + c.getMethod() + } - public void runTests(Class c) + public String runTests(Class c) { - ArrayList myAnnotationMethod = new ArrayList(); Method[] methods = c.getDeclaredMethods(); - - while(c != Object.class) - { - for(int i = 0; i < methods.length; i++) - { - if(methods[i].isAnnotationPresent(Test.class)) + for(int i = 0; i < methods.length; i++) { - runTest(c, methods[i].getName() ); + if(methods[i].isAnnotationPresent(Test.class)) + { + runTest(c, methods[i].getName()); + System.out.println(printAnnotations(methods[i])); + return printAnnotations(methods[i]); + } } - } + return "No Results"; + } + private String printAnnotations(Method method) { + Annotation[] methodAnnotations = method.getDeclaredAnnotations(); + String methodName= method.getName(); + if(methodAnnotations.length < 1) + { + return "There were no annotations associated with the method " + methodName; } + for(Annotation annotation : methodAnnotations) + { + String annotationName = annotation.getClass().getName(); + return annotationName; + } + return "Fuck"; + } - + public static void main(String[] args) + { + UnitCornTestRunner tester = new UnitCornTestRunner(); + Double adouble = 2.332; +// Class aclass = +// tester.runTests(Test.class); } diff --git a/src/test/java/TestUnitCornTestRunner.java b/src/test/java/TestUnitCornTestRunner.java new file mode 100644 index 0000000..e3c162b --- /dev/null +++ b/src/test/java/TestUnitCornTestRunner.java @@ -0,0 +1,43 @@ +import org.junit.Assert; +import org.junit.Test; +import unitcorn.UnitCornTestRunner; + +/** + * Created by luisgarcia on 5/5/17. + */ +public class TestUnitCornTestRunner +{ + UnitCornTestRunner tester = new UnitCornTestRunner(); + Double aDouble = 3.333; + Class aClass = aDouble.getClass(); + + + @Test + public void testRunTests() + { + TestUnitCornTestRunner paco = new TestUnitCornTestRunner(); + //given + String expected = "com.sun.proxy.$Proxy1"; + + //when + String actual = tester.runTests(paco.getClass()); + + //then + Assert.assertEquals(expected, actual); + } + + @Test + public void testRunTestNoResults() + { + //given + String expected = "No Results"; + + //when + String actual = tester.runTests(aClass); + + //then + Assert.assertEquals(expected, actual); + } + + +} From b4d82806fa1fcd938ecac75b87e5ebe759f51afb Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Sat, 6 May 2017 13:28:03 -0400 Subject: [PATCH 6/7] finishing up unitcorn --- .idea/workspace.xml | 113 +++++++----------- src/main/java/unitcorn/Result.java | 18 +++ .../java/unitcorn/UnitCornTestRunner.java | 31 ++++- 3 files changed, 88 insertions(+), 74 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c5b4845..4b20e0a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,8 +3,7 @@ - - + @@ -27,25 +26,11 @@ - - - - - - - - - - - - - - - - + + @@ -53,21 +38,11 @@ - - + + - - - - - - - - - - - + @@ -75,14 +50,12 @@ - - + + - - - - - + + + @@ -115,8 +88,8 @@ @@ -128,8 +101,8 @@ @@ -772,7 +745,7 @@ @@ -783,55 +756,55 @@ - - + + - - + + - + - + - + - + - + - + - - + - + - + - + - + @@ -905,7 +878,7 @@ - + @@ -915,28 +888,28 @@ - + - - - - - + + + - + - - + + + + - - + + diff --git a/src/main/java/unitcorn/Result.java b/src/main/java/unitcorn/Result.java index 140341d..b9fabb2 100644 --- a/src/main/java/unitcorn/Result.java +++ b/src/main/java/unitcorn/Result.java @@ -5,5 +5,23 @@ */ public class Result { + private boolean pass; + private String method; + private String theClass; + + public Result(boolean pass, String method, String theClass) + { + this.pass = pass; + this.method = method; + this.theClass = theClass; + } + + public void printResutl() + { + System.out.println("Class Tested: " + theClass); + System.out.println("Method Tested: " + method); + System.out.println("Pass: " + pass); + } + } diff --git a/src/main/java/unitcorn/UnitCornTestRunner.java b/src/main/java/unitcorn/UnitCornTestRunner.java index 50fdafa..b9d44a0 100644 --- a/src/main/java/unitcorn/UnitCornTestRunner.java +++ b/src/main/java/unitcorn/UnitCornTestRunner.java @@ -5,6 +5,7 @@ import org.junit.Test; import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -14,10 +15,20 @@ */ public class UnitCornTestRunner { - public void runTest(Class c, String methodName) + public Result runTest(Class c, String methodName) { - c.getMethod() + boolean pass = false; + try { + Method m = c.getMethod(methodName); + Object obj = c.newInstance(); + pass = methodPass(m, obj); + + }catch (Exception e){ + System.err.println(e.getMessage()); + } + Result myResult = new Result(pass,methodName, c.getName()); + return myResult; } public String runTests(Class c) @@ -28,7 +39,6 @@ public String runTests(Class c) if(methods[i].isAnnotationPresent(Test.class)) { runTest(c, methods[i].getName()); - System.out.println(printAnnotations(methods[i])); return printAnnotations(methods[i]); } } @@ -51,12 +61,25 @@ private String printAnnotations(Method method) { return "Fuck"; } + public boolean methodPass(Method method, Object obj) + { + boolean pass = false; + try { + method.invoke(obj); + pass = true; + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + return pass; + } + public static void main(String[] args) { UnitCornTestRunner tester = new UnitCornTestRunner(); Double adouble = 2.332; // Class aclass = -// tester.runTests(Test.class); } From 7ff249e524195252bc33001dba9365af6d490cb3 Mon Sep 17 00:00:00 2001 From: Luis Garcia Date: Sat, 6 May 2017 18:43:59 -0400 Subject: [PATCH 7/7] Still tweaking --- .idea/workspace.xml | 277 +++++++++--------- .../java/garcia/luis/TypeInformation.java | 137 +++++---- src/main/java/unitcorn/Result.java | 5 + .../java/unitcorn/UnitCornTestRunner.java | 7 - src/test/java/TestTypeInformation.java | 8 +- src/test/java/TestUnitCornTestRunner.java | 18 ++ 6 files changed, 235 insertions(+), 217 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 4b20e0a..56ef2ab 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,8 +3,11 @@ + + + @@ -26,35 +29,25 @@ - - + + - - + + + + - - + + - - - - - - - - - - - - - - + + @@ -85,11 +78,11 @@ @@ -101,8 +94,8 @@ @@ -119,7 +112,6 @@ - @@ -146,14 +138,6 @@ + @@ -241,15 +226,36 @@ - - + + + + + + + + + + - - - + - + - - - - - - - + @@ -703,6 +690,12 @@ + project + + + + + @@ -719,19 +712,19 @@ - - - - - + + + + + - - - - - + + + + + @@ -745,28 +738,29 @@ - - + + - - + + - - + + - - + + - - + + - - + + @@ -782,42 +776,42 @@ - - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + - + - - + + + @@ -828,7 +822,7 @@ - @@ -846,7 +840,6 @@ - @@ -858,60 +851,54 @@ - - - - - - - - - + + - - + + - + - - + + - - - + + - + - - - + + + + + - + - - - - - + + + - + - - + + + + diff --git a/src/main/java/garcia/luis/TypeInformation.java b/src/main/java/garcia/luis/TypeInformation.java index b2394f7..1a48766 100644 --- a/src/main/java/garcia/luis/TypeInformation.java +++ b/src/main/java/garcia/luis/TypeInformation.java @@ -1,5 +1,6 @@ package garcia.luis; +import javax.sound.midi.Soundbank; import java.lang.reflect.*; import java.util.ArrayList; @@ -9,76 +10,67 @@ public class TypeInformation { - public boolean classImplementsInterface(Object obj, Class cl) + public boolean classImplementsInterface(Object obj, String theInterface) { Class classObject = obj.getClass(); - if(classObject.isInstance(cl)) - { - return true; - } - else - { - return false; - } + Class [] interfaces = classObject.getInterfaces(); + for(int i = 0; i < interfaces.length; i++) + { + if(theInterface.equals(interfaces[i].getName())) + { + return true; + } + } + return false; } - public boolean classImplementsInterface(Class obj, Class cl) + public boolean classImplementsInterface(Class obj, String theInterface) { - - if(cl.isInstance(obj)) - { - return true; - } - else + Class [] interfaces = obj.getInterfaces(); + for(int i = 0; i < interfaces.length; i++) { - return false; + if(theInterface.equals(interfaces[i].getName())) + { + return true; + } } + return false; } - public boolean classImplementsInterface(String obj, Class cl) + public boolean classImplementsInterface(String obj, String theInterface) throws ClassNotFoundException { - Class classObject = obj.getClass(); - if(cl.isInstance(obj)) + Class cl = Class.forName(obj); + Class [] interfaces = cl.getInterfaces(); + for(int i = 0; i < interfaces.length; i++) { - return true; - } - else - { - return false; + if(theInterface.equals(interfaces[i].getName())) + { + return true; + } } + return false; + } - public void listAllMembers(Class obj) + public void listAllMembers(Object obj) { Class cl = obj.getClass(); - Constructor[] constructors = cl.getDeclaredConstructors(); - Field [] fields = cl.getDeclaredFields(); - Method [] methods = cl.getDeclaredMethods(); - - System.out.println("Constructors"); - for(int i = 0; i < constructors.length; i++) + ArrayList myList = getSuperClass(obj); + System.out.println(myList.size()); + for(int i=0; i obj) + public void getClassHierarchy(Object obj) { String tab =""; System.out.println("Class Hierarchy"); - ArrayList mySuperList = getSuperClass(obj); + ArrayList mySuperList = getSuperClass(obj.getClass()); for(int i = mySuperList.size()-1;i >= 0; i--) { @@ -91,7 +83,7 @@ public void getClassHierarchy(Class obj) } - public ArrayList getSuperClass(Class obj) + public ArrayList getSuperClass(Object obj) { ArrayList superClassList = new ArrayList(); String superClass = Object.class.getName(); @@ -99,8 +91,8 @@ public ArrayList getSuperClass(Class obj) do{ - superClassList.add(obj.getSuperclass().getName()); - obj = obj.getSuperclass(); + superClassList.add(obj.getClass().getSuperclass().getName()); + obj = obj.getClass().getSuperclass(); } while (!superClass.equals(superClassList.get(i++))); @@ -109,31 +101,54 @@ public ArrayList getSuperClass(Class obj) } - public ArrayList instantiateClassHierarchy(Class obj) + public ArrayList instantiateClassHierarchy(Object obj) { - ArrayList myList = getSuperClass(obj); + ArrayList myList = getSuperClass(obj); ArrayList instance = new ArrayList(); for(int i = 0; i < myList.size(); i++) { if(obj.getClass().isInstance(myList.get(i))) { - try { - Object m = Class.forName(obj.getClass().getName()).newInstance(); - instance.add(m); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } + instance.add(obj); } } return instance; } + public void printAllMembers(Object obj) + { + Constructor[] constructors = obj.getClass().getDeclaredConstructors(); + Field [] fields = obj.getClass().getDeclaredFields(); + Method [] methods = obj.getClass().getDeclaredMethods(); + + System.out.println("Constructors"); + for(int i = 0; i < constructors.length; i++) + { + System.out.println(constructors[i]); + } + System.out.println("Fields"); + for(int i = 0; i < fields.length; i++) + { + System.out.println(fields[i]); + } + System.out.println("Methods"); + for(int i = 0; i < methods.length; i++) + { + System.out.println(methods[i]); + } + System.out.println(); + } + + public static void main(String[] args) + { + TypeInformation test = new TypeInformation(); + String myString = "Paco"; + Double myDouble = 2.33; + ArrayList myList = test.instantiateClassHierarchy(myString); + System.out.println(myList); + } } diff --git a/src/main/java/unitcorn/Result.java b/src/main/java/unitcorn/Result.java index b9fabb2..ba75c17 100644 --- a/src/main/java/unitcorn/Result.java +++ b/src/main/java/unitcorn/Result.java @@ -16,6 +16,11 @@ public Result(boolean pass, String method, String theClass) this.theClass = theClass; } + public boolean getPass() + { + return pass; + } + public void printResutl() { System.out.println("Class Tested: " + theClass); diff --git a/src/main/java/unitcorn/UnitCornTestRunner.java b/src/main/java/unitcorn/UnitCornTestRunner.java index b9d44a0..a4f2076 100644 --- a/src/main/java/unitcorn/UnitCornTestRunner.java +++ b/src/main/java/unitcorn/UnitCornTestRunner.java @@ -75,12 +75,5 @@ public boolean methodPass(Method method, Object obj) return pass; } - public static void main(String[] args) - { - UnitCornTestRunner tester = new UnitCornTestRunner(); - Double adouble = 2.332; -// Class aclass = - - } } diff --git a/src/test/java/TestTypeInformation.java b/src/test/java/TestTypeInformation.java index 3e857c7..ee71f97 100644 --- a/src/test/java/TestTypeInformation.java +++ b/src/test/java/TestTypeInformation.java @@ -5,6 +5,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Comparator; /** * Created by luisgarcia on 5/4/17. @@ -19,13 +20,12 @@ public class TestTypeInformation @Test - public void testImplementsInterface() - { + public void testImplementsInterface() throws ClassNotFoundException { //given boolean expected = false; //when - boolean actual = test.classImplementsInterface(strObj, cl); + boolean actual = test.classImplementsInterface(strObj.getClass(), "Comparable"); //then Assert.assertEquals(expected, actual); @@ -54,7 +54,7 @@ public void testHierarchy() String expected = "java.lang.Object"; //when - String actual = myList.get(1); + String actual = myList.get(0); //then Assert.assertEquals(expected, actual); diff --git a/src/test/java/TestUnitCornTestRunner.java b/src/test/java/TestUnitCornTestRunner.java index e3c162b..979ffe0 100644 --- a/src/test/java/TestUnitCornTestRunner.java +++ b/src/test/java/TestUnitCornTestRunner.java @@ -1,5 +1,6 @@ import org.junit.Assert; import org.junit.Test; +import unitcorn.Result; import unitcorn.UnitCornTestRunner; /** @@ -39,5 +40,22 @@ public void testRunTestNoResults() Assert.assertEquals(expected, actual); } + @Test + public void testRunTest() + { + TestUnitCornTestRunner paco = new TestUnitCornTestRunner(); + String myMethod = tester.runTests(paco.getClass()); + + //given + Result myResult = tester.runTest(paco.getClass(), myMethod); + boolean expected = false; + + //when + boolean actual = myResult.getPass(); + + //then + Assert.assertEquals(expected, actual); + } + }