diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..9af5234 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 32858aa..0000000 --- a/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -*.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* diff --git a/.idea/TypeInformation.iml b/.idea/TypeInformation.iml new file mode 100644 index 0000000..d8596f2 --- /dev/null +++ b/.idea/TypeInformation.iml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..b26911b --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..1c24f9a --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ 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__log4j_log4j_1_2_17.xml b/.idea/libraries/Maven__log4j_log4j_1_2_17.xml new file mode 100644 index 0000000..e383c1b --- /dev/null +++ b/.idea/libraries/Maven__log4j_log4j_1_2_17.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/libraries/Maven__org_slf4j_slf4j_api_1_7_5.xml b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_5.xml new file mode 100644 index 0000000..6f808f1 --- /dev/null +++ b/.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_5.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_7_5.xml b/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_7_5.xml new file mode 100644 index 0000000..df1d383 --- /dev/null +++ b/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_7_5.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..9896aeb --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7f5ebd1 --- /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..19d2091 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,1493 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1493985462458 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + TypeInformation + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2f128a0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + kalaygian.dennis + typeinformation + 1.0-SNAPSHOT + jar + + typeinformation + http://maven.apache.org + + + UTF-8 + + + + + + junit + junit + 4.12 + test + + + + org.slf4j + slf4j-api + 1.7.5 + + + + org.slf4j + slf4j-log4j12 + 1.7.5 + + + + diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..2e95f8e Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/java/kalaygian/dennis/part1/Display.java b/src/main/java/kalaygian/dennis/part1/Display.java new file mode 100644 index 0000000..6aa056c --- /dev/null +++ b/src/main/java/kalaygian/dennis/part1/Display.java @@ -0,0 +1,7 @@ +package kalaygian.dennis.part1; + +/** + * Created by denniskalaygian on 5/5/17. + */ +public class Display { +} diff --git a/src/main/java/kalaygian/dennis/part1/FamilyTree.java b/src/main/java/kalaygian/dennis/part1/FamilyTree.java new file mode 100644 index 0000000..04d05b1 --- /dev/null +++ b/src/main/java/kalaygian/dennis/part1/FamilyTree.java @@ -0,0 +1,85 @@ +package kalaygian.dennis.part1; +import java.util.ArrayList; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Constructor; + + +/** + * Created by denniskalaygian on 5/5/17. + */ +public class FamilyTree { + + private Class originalClass; + + public FamilyTree(Class originalClass) { + this.originalClass = originalClass; + } + + public Class getOriginalClass() { + return originalClass; + } + + public void setOriginalClass(Class originalClass) { + this.originalClass = originalClass; + } + + public Boolean classImplementsInterface(String interfce) throws ClassNotFoundException { + Class class1 = originalClass; + return Class.forName(interfce).isAssignableFrom(class1); + } + + public String getClassHierarchy() throws ClassNotFoundException { + int count = getClassHierarchyLength(); + Class[] classList = createClassHierarchyArray(count); + return formatClassHierarchyArray(classList); + } + + private int getClassHierarchyLength() throws ClassNotFoundException{ + Class class1 = originalClass; + int count = 0; + while(class1.getSuperclass() != null){ + count += 1; + class1 = class1.getSuperclass(); + } + return count + 1; + } + + private Class[] createClassHierarchyArray(int count) throws ClassNotFoundException { + Class class1 = originalClass; + Class[] classList = new Class[count]; + classList[0] = Class.forName("java.lang.Object"); + for(int index = count; index > 0; index--){ + classList[index - 1] = class1; + class1 = class1.getSuperclass(); + } + return classList; + } + + private String formatClassHierarchyArray(Class[] classList){ + String spaces = ""; + String returnHierarchy = ""; + for(int index = 0; index < classList.length; index++){ + returnHierarchy += spaces + classList[index].getName() + "\n"; + spaces += " "; + } + return returnHierarchy; + } + + public ArrayList instantiateClassHierarchy() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException { + int count = getClassHierarchyLength(); + Class[] classList = createClassHierarchyArray(count); + ArrayList returnList = new ArrayList(); + for(int index = 0; index < count; index++){ + + try{ + Object element = classList[index].newInstance(); + returnList.add(element); + } catch(Exception e) { + Object element = null; + returnList.add(element); + } + } + return returnList; + } + +} diff --git a/src/main/java/kalaygian/dennis/part1/Main.java b/src/main/java/kalaygian/dennis/part1/Main.java new file mode 100644 index 0000000..d8e8f72 --- /dev/null +++ b/src/main/java/kalaygian/dennis/part1/Main.java @@ -0,0 +1,10 @@ +package kalaygian.dennis.part1; +import java.util.ArrayList; + + +public class Main +{ + public static void main( String[] args ) throws ClassNotFoundException { + + } +} diff --git a/src/main/java/kalaygian/dennis/unitcorn/Result.java b/src/main/java/kalaygian/dennis/unitcorn/Result.java new file mode 100644 index 0000000..2535901 --- /dev/null +++ b/src/main/java/kalaygian/dennis/unitcorn/Result.java @@ -0,0 +1,28 @@ +package kalaygian.dennis.unitcorn; +import java.util.ArrayList; + +/** + * Created by denniskalaygian on 5/6/17. + */ +public class Result { + + String methodName; + String result; + + public Result(String methodName, String result) { + this.methodName = methodName; + this.result = result; + } + + public String getResult() { + return result; + } + + public String getMethodName() { + return methodName; + } + + public String toString() { + return "Test result of " + methodName + ": " + result + ".\n"; + } +} diff --git a/src/main/java/kalaygian/dennis/unitcorn/UnitCornTestRunner.java b/src/main/java/kalaygian/dennis/unitcorn/UnitCornTestRunner.java new file mode 100644 index 0000000..7f003a8 --- /dev/null +++ b/src/main/java/kalaygian/dennis/unitcorn/UnitCornTestRunner.java @@ -0,0 +1,8 @@ +package kalaygian.dennis.unitcorn; + + +/** + * Created by denniskalaygian on 5/6/17. + */ +public class UnitCornTestRunner { +} diff --git a/src/test/.DS_Store b/src/test/.DS_Store new file mode 100644 index 0000000..70c1ff3 Binary files /dev/null and b/src/test/.DS_Store differ diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store new file mode 100644 index 0000000..f667c65 Binary files /dev/null and b/src/test/java/.DS_Store differ diff --git a/src/test/java/kalaygian/.DS_Store b/src/test/java/kalaygian/.DS_Store new file mode 100644 index 0000000..b7861c8 Binary files /dev/null and b/src/test/java/kalaygian/.DS_Store differ diff --git a/src/test/java/kalaygian/dennis/testpart1/TestFamilyTree.java b/src/test/java/kalaygian/dennis/testpart1/TestFamilyTree.java new file mode 100644 index 0000000..b7056b7 --- /dev/null +++ b/src/test/java/kalaygian/dennis/testpart1/TestFamilyTree.java @@ -0,0 +1,109 @@ +package kalaygian.dennis.testpart1; + +import kalaygian.dennis.part1.FamilyTree; +import org.junit.Test; +import org.junit.Assert; + +import java.util.ArrayList; + + +public class TestFamilyTree{ + + @Test + public void testClassImplementsInterfaceReturnType() throws ClassNotFoundException { + //Given + FamilyTree familyTree = new FamilyTree(Class.forName("java.util.ArrayList")); + Class expectedReturnType = Boolean.class; + //When + Class returnType = familyTree.classImplementsInterface("java.util.List").getClass(); + //Then + Assert.assertEquals("Method is returning the wrong data type", expectedReturnType, returnType); + } + + @Test + public void testClassImplementsInterface() throws ClassNotFoundException { + //Given + FamilyTree familyTree = new FamilyTree(Class.forName("java.util.ArrayList")); + boolean expectedOutcome = true; + //When + Boolean methodOutcome = familyTree.classImplementsInterface("java.util.List"); + //Then + Assert.assertEquals("Method is returning the wrong boolean", expectedOutcome, methodOutcome); + } + + @Test + public void testGetClassHierarchyReturnType() throws ClassNotFoundException { + //Given + FamilyTree familyTree = new FamilyTree(Class.forName("java.util.AbstractList")); + Class expectedReturnType = String.class; + //When + Class returnType = familyTree.getClassHierarchy().getClass(); + //Then + Assert.assertEquals("Method is returning the wrong data type", expectedReturnType, returnType); + } + + @Test + public void testGetClassHierarchy() throws ClassNotFoundException { + //Given + FamilyTree familyTree = new FamilyTree(Class.forName("java.util.AbstractList")); + String expectedValue = "java.lang.Object" + "\n" + " " + "java.util.AbstractCollection" + "\n" + " " + "java.util.AbstractList" + "\n"; + //When + String returnValue = familyTree.getClassHierarchy(); + //Then + Assert.assertEquals("Method is not returning the right value", expectedValue, returnValue); + } + + /*@Test + public void testListAllMembersReturnType() throws ClassNotFoundException { + //Given + FamilyTree familyTree = new FamilyTree(Class.forName("java.lang.Boolean")); + Class expectedReturnType = String.class; + //When + Class returnType = familyTree.listAllMembers().getClass(); + //Then + Assert.assertEquals("Method is returning the wrong data type", expectedReturnType, returnType); + } + + @Test + public void testListAllMembers() throws ClassNotFoundException { + //Given + FamilyTree familyTree = new FamilyTree(Class.forName("java.lang.Boolean")); + String expectedValue = "java.lang.Object" + "\n" + " " + "java.util.AbstractCollection" + "\n" + " " + "java.util.AbstractList" + "\n"; + //When + String returnValue = familyTree.getClassHierarchy(); + //Then + Assert.assertEquals("Method is not returning the right value", expectedValue, returnValue); + }*/ + + @Test + public void testInstantiateClassHierarchyReturnType() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException { + //Given + FamilyTree familyTree = new FamilyTree(Class.forName("java.util.ArrayList")); + Class expectedReturnType = ArrayList.class; + //When + Class returnType = familyTree.instantiateClassHierarchy().getClass(); + //Then + Assert.assertEquals("Method is returning the wrong data type", expectedReturnType, returnType); + } + + @Test + public void testInstantiateClassHierarchy() throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException { + //Given + FamilyTree familyTree = new FamilyTree(Class.forName("java.util.ArrayList")); + ArrayList expectedList = new ArrayList(); + Object element1 = ArrayList.class.newInstance(); + Object element2 = null; + Object element3 = null; + Object element4 = Object.class.newInstance(); + expectedList.add(element4); + expectedList.add(element3); + expectedList.add(element2); + expectedList.add(element1); + ArrayList returnList; + //When + returnList = familyTree.instantiateClassHierarchy(); + //Then + Assert.assertEquals("Method is not returning the right value", expectedList, returnList); + } + +} diff --git a/src/test/java/kalaygian/dennis/testunitcorn/ImitationTest.java b/src/test/java/kalaygian/dennis/testunitcorn/ImitationTest.java new file mode 100644 index 0000000..7e6e717 --- /dev/null +++ b/src/test/java/kalaygian/dennis/testunitcorn/ImitationTest.java @@ -0,0 +1,35 @@ +package kalaygian.dennis.testunitcorn; +import org.junit.Test; +import org.junit.Assert; +import java.util.AbstractList; + + +/** + * Created by denniskalaygian on 5/7/17. + */ +public class ImitationTest { + + @Test + public void testEqualityPass() { + //Given + int num1 = 2; + int num2 = 2; + //When + boolean result = (num1 == num2); + //Then + Assert.assertTrue("The two numbers are not equal to one another", result); + } + + // This one is designed to fail + @Test + public void testEqualityFail(){ + //Given + int num1 = 1; + int num2 = 2; + //When + boolean result = (num1 == num2); + //Then + Assert.assertTrue("The two numbers are not equal to each other", result); + } + +} diff --git a/src/test/java/kalaygian/dennis/testunitcorn/TestUnitCornTestRunner.java b/src/test/java/kalaygian/dennis/testunitcorn/TestUnitCornTestRunner.java new file mode 100644 index 0000000..97c6639 --- /dev/null +++ b/src/test/java/kalaygian/dennis/testunitcorn/TestUnitCornTestRunner.java @@ -0,0 +1,8 @@ +package kalaygian.dennis.testunitcorn; + +/** + * Created by denniskalaygian on 5/6/17. + */ +public class TestUnitCornTestRunner { + +} diff --git a/target/classes/kalaygian/dennis/part1/Display.class b/target/classes/kalaygian/dennis/part1/Display.class new file mode 100644 index 0000000..b2cfd7b Binary files /dev/null and b/target/classes/kalaygian/dennis/part1/Display.class differ diff --git a/target/classes/kalaygian/dennis/part1/FamilyTree.class b/target/classes/kalaygian/dennis/part1/FamilyTree.class new file mode 100644 index 0000000..f391263 Binary files /dev/null and b/target/classes/kalaygian/dennis/part1/FamilyTree.class differ diff --git a/target/classes/kalaygian/dennis/part1/Main.class b/target/classes/kalaygian/dennis/part1/Main.class new file mode 100644 index 0000000..6fc784d Binary files /dev/null and b/target/classes/kalaygian/dennis/part1/Main.class differ diff --git a/target/classes/kalaygian/dennis/unitcorn/Result.class b/target/classes/kalaygian/dennis/unitcorn/Result.class new file mode 100644 index 0000000..8e3bec4 Binary files /dev/null and b/target/classes/kalaygian/dennis/unitcorn/Result.class differ diff --git a/target/classes/kalaygian/dennis/unitcorn/UnitCornTestRunner.class b/target/classes/kalaygian/dennis/unitcorn/UnitCornTestRunner.class new file mode 100644 index 0000000..afb7dd2 Binary files /dev/null and b/target/classes/kalaygian/dennis/unitcorn/UnitCornTestRunner.class differ diff --git a/target/test-classes/kalaygian/dennis/testpart1/TestFamilyTree.class b/target/test-classes/kalaygian/dennis/testpart1/TestFamilyTree.class new file mode 100644 index 0000000..1a6d718 Binary files /dev/null and b/target/test-classes/kalaygian/dennis/testpart1/TestFamilyTree.class differ diff --git a/target/test-classes/kalaygian/dennis/testunitcorn/ImitationTest.class b/target/test-classes/kalaygian/dennis/testunitcorn/ImitationTest.class new file mode 100644 index 0000000..0dd4400 Binary files /dev/null and b/target/test-classes/kalaygian/dennis/testunitcorn/ImitationTest.class differ diff --git a/target/test-classes/kalaygian/dennis/testunitcorn/TestUnitCornTestRunner.class b/target/test-classes/kalaygian/dennis/testunitcorn/TestUnitCornTestRunner.class new file mode 100644 index 0000000..cef6f9c Binary files /dev/null and b/target/test-classes/kalaygian/dennis/testunitcorn/TestUnitCornTestRunner.class differ