@Test public void testprintClassNoBuffers() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); Field supers = UMLArrows.class.getDeclaredField("supers"); supers.setAccessible(true); Field interfaces = UMLArrows.class.getDeclaredField("interfaces"); interfaces.setAccessible(true); Field uses = UMLArrows.class.getDeclaredField("uses"); uses.setAccessible(true); Field fields = UMLArrows.class.getDeclaredField("fields"); fields.setAccessible(true); Field fieldbuffer = UMLArrows.class.getDeclaredField("fieldBuffer"); fieldbuffer.setAccessible(true); Field methodbuffer = UMLArrows.class.getDeclaredField("methodBuffer"); methodbuffer.setAccessible(true); Field className = UMLArrows.class.getDeclaredField("className"); className.setAccessible(true); className.set(arrows, "test"); supers.set(arrows, ""); interfaces.set(arrows, new ArrayList<String>()); uses.set(arrows, new ArrayList<String>()); fields.set(arrows, new ArrayList<String>()); fieldbuffer.set(arrows, new StringBuffer()); methodbuffer.set(arrows, new StringBuffer()); arrows.printClass(); assertEquals( " test [\n shape=\"record\" label = \"{test||\n}\"\n];\n", outContent.toString()); }
@Test public void testprintClass() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); Field supers = UMLArrows.class.getDeclaredField("supers"); supers.setAccessible(true); Field interfaces = UMLArrows.class.getDeclaredField("interfaces"); interfaces.setAccessible(true); Field uses = UMLArrows.class.getDeclaredField("uses"); uses.setAccessible(true); Field fields = UMLArrows.class.getDeclaredField("fields"); fields.setAccessible(true); Field fieldbuffer = UMLArrows.class.getDeclaredField("fieldBuffer"); fieldbuffer.setAccessible(true); Field methodbuffer = UMLArrows.class.getDeclaredField("methodBuffer"); methodbuffer.setAccessible(true); Field className = UMLArrows.class.getDeclaredField("className"); className.setAccessible(true); className.set(arrows, "test"); supers.set(arrows, ""); interfaces.set(arrows, new ArrayList<String>()); uses.set(arrows, new ArrayList<String>()); fields.set(arrows, new ArrayList<String>()); StringBuffer fTemp = new StringBuffer(); fTemp.append("I was thinking about this buffer and it was a good idea."); StringBuffer mTemp = new StringBuffer(); mTemp.append("This is a powerful MethodBuffer."); fieldbuffer.set(arrows, fTemp); methodbuffer.set(arrows, mTemp); arrows.printClass(); assertEquals( " test [\n shape=\"record\" label = \"{test|I was thinking about this buffer and it was a good idea.|This is a powerful MethodBuffer.\n}\"\n];\n", outContent.toString()); }
@Test public void testaddFieldDescSingletonStaticOnly() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); Field whitelist = WorkerForArrows.class.getDeclaredField("whitelist"); whitelist.setAccessible(true); ArrayList<String> whitelistv1 = new ArrayList<String>(Arrays.asList("TestMisfitsPackage_UMLArrowsTest")); whitelist.set(arrows, whitelistv1); Field fields = UMLArrows.class.getDeclaredField("fields"); fields.setAccessible(true); SingletonDetector detect = new SingletonDetector("red", "purple"); Field detector = UMLArrows.class.getDeclaredField("detectors"); detector.setAccessible(true); ArrayList<PatternDetector> pattern = new ArrayList<PatternDetector>(); pattern.add(detect); detector.set(arrows, pattern); ArrayList<String> fieldsarray = new ArrayList<String>(); fields.set(arrows, new ArrayList<String>()); Field className = UMLArrows.class.getDeclaredField("className"); className.setAccessible(true); // We must avoid having the stripper from touching this string String toAdd = "TestMisfitsPackage_UMLArrowsTest"; String desc = "LTestMisfitsPackage/UMLArrowsTest;"; className.set(arrows, toAdd); fieldsarray.add(toAdd); int access = Opcodes.ACC_STATIC; // An Opcode of only static should leave // isSingle as false arrows.addFieldDesc(desc, access); assertEquals(false, detect.isDetected()); }
@Test public void testJComponentForCompositeLeaf() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); CompositeDetector detect = new CompositeDetector("red", "purple"); Field detector = UMLArrows.class.getDeclaredField("detectors"); detector.setAccessible(true); Field classesField = UMLArrows.class.getDeclaredField("classes"); classesField.setAccessible(true); ArrayList<PatternDetector> pattern = new ArrayList<PatternDetector>(); pattern.add(detect); detector.set(arrows, pattern); // Field classesField = UMLArrows.class.getDeclaredField("classes"); // classesField.setAccessible(true); String[] testString = new String[3]; testString[0] = "java.awt.Component"; testString[1] = "java.awt.Container"; testString[2] = "javax.swing.JComponent"; DesignParser.makeUML(testString); ArrayList<ClassContainer> classes = (ArrayList<ClassContainer>) classesField.get(arrows); for (ClassContainer cls : classes) { if (cls.getClassName().equals("javax_swing_JComponent")) { assertTrue(cls.getLabel().contains("Leaf")); } } }
@Test public void testaddToMethodBufferNothing() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { String toAdd = ""; UMLArrows arrows = UMLArrows.getInstance(); Field methodBuffer = UMLArrows.class.getDeclaredField("methodBuffer"); methodBuffer.setAccessible(true); StringBuffer currentBuffer = (StringBuffer) methodBuffer.get(arrows); String newBuffer = (currentBuffer.toString() + toAdd); arrows.addToMethodBuffer(toAdd); assertEquals(newBuffer, methodBuffer.get(arrows).toString()); }
@Test public void testaddToFieldBufferSymbols() throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { String toAdd = "(#)^%@#%^@#$)@#$*@#&$)@!_)*"; UMLArrows arrows = UMLArrows.getInstance(); Field fieldBuffer = UMLArrows.class.getDeclaredField("fieldBuffer"); fieldBuffer.setAccessible(true); StringBuffer currentBuffer = (StringBuffer) fieldBuffer.get(arrows); String newBuffer = (currentBuffer.toString() + toAdd); arrows.addToFieldBuffer(toAdd); assertEquals(newBuffer, fieldBuffer.get(arrows).toString()); }
@Test public void testaddMethodToBuffer() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); Field whitelist = WorkerForArrows.class.getDeclaredField("whitelist"); whitelist.setAccessible(true); ArrayList<String> whitelistv1 = new ArrayList<String>(Arrays.asList("java_lang_Object")); whitelist.set(arrows, whitelistv1); Field methodbuffer = UMLArrows.class.getDeclaredField("methodBuffer"); methodbuffer.setAccessible(true); methodbuffer.set(arrows, new StringBuffer()); arrows.addMethodToBuffer(Opcodes.ACC_PUBLIC, "test", "()Ljava/lang/Object;"); assertEquals("+test([]) : java_lang_Object\\l ", methodbuffer.get(arrows).toString()); }
@Test public void testsetSuperSpecial() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); Field whitelist = WorkerForArrows.class.getDeclaredField("whitelist"); whitelist.setAccessible(true); ArrayList<String> whitelistv1 = new ArrayList<String>(Arrays.asList("#$%^&*(<>?:\"{}';'")); whitelist.set(arrows, whitelistv1); Field supers = UMLArrows.class.getDeclaredField("supers"); supers.setAccessible(true); // We must avoid having the stripper from touching this string String theSuper = "#$%^&*(<>?:\"{}';'"; arrows.setSuper(theSuper); assertEquals(theSuper, supers.get(arrows)); }
@Test public void testaddUses() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); Field whitelist = WorkerForArrows.class.getDeclaredField("whitelist"); whitelist.setAccessible(true); ArrayList<String> whitelistv1 = new ArrayList<String>(Arrays.asList("int", "double", "byte")); whitelist.set(arrows, whitelistv1); Field uses = UMLArrows.class.getDeclaredField("uses"); uses.setAccessible(true); uses.set(arrows, new ArrayList<String>()); ArrayList<String> usesarray = new ArrayList<String>(Arrays.asList("int", "double", "byte")); String desc = "(IDB)Ljava/lang/Object"; arrows.addUses(desc); assertEquals(usesarray, uses.get(arrows)); }
@Test public void testresetUMLArrows() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { int classesSize; UMLArrows arrows = UMLArrows.getInstance(); Field currentClass = UMLArrows.class.getDeclaredField("currentClass"); currentClass.setAccessible(true); classesSize = arrows.getClasses().size(); arrows.setCurrentClass("DecoratorDetector"); assertEquals(0, classesSize); ClassContainer curClass = (ClassContainer) currentClass.get(arrows); arrows.setCurrentClass("DecoratorDetector"); classesSize = arrows.getClasses().size(); assertEquals(1, classesSize); assertEquals(curClass, arrows.getClasses().get(0)); }
@SuppressWarnings("unchecked") @Test public void testaddUseEmptyString() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); Field whitelist = WorkerForArrows.class.getDeclaredField("whitelist"); whitelist.setAccessible(true); ArrayList<String> whitelistv1 = new ArrayList<String>(Arrays.asList("")); whitelist.set(arrows, whitelistv1); Field uses = UMLArrows.class.getDeclaredField("uses"); uses.setAccessible(true); ArrayList<String> usesarray = (ArrayList<String>) uses.get(arrows); String toAdd = ""; usesarray.add(toAdd); arrows.addUse(toAdd); assertEquals(usesarray, uses.get(arrows)); }
@SuppressWarnings("unchecked") @Test public void testaddInterfaceNumerics() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); Field whitelist = WorkerForArrows.class.getDeclaredField("whitelist"); whitelist.setAccessible(true); ArrayList<String> whitelistv1 = new ArrayList<String>(Arrays.asList("0937240432")); whitelist.set(arrows, whitelistv1); Field interfaces = UMLArrows.class.getDeclaredField("interfaces"); interfaces.setAccessible(true); ArrayList<String> interfacesarray = (ArrayList<String>) interfaces.get(arrows); String toAdd = "0937240432"; interfacesarray.add(toAdd); arrows.addInterface(toAdd); assertEquals(interfacesarray, interfaces.get(arrows)); }
// private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); // private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); // // @Before // public void setUpStreams() { // System.setOut(new PrintStream(outContent)); // System.setErr(new PrintStream(errContent)); // } // // @After // public void cleanUpStreams() { // System.setOut(null); // System.setErr(null); // } // @Test public void testContainerForComposite() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); CompositeDetector detect = new CompositeDetector("red", "purple"); Field detector = UMLArrows.class.getDeclaredField("detectors"); detector.setAccessible(true); ArrayList<PatternDetector> pattern = new ArrayList<PatternDetector>(); pattern.add(detect); detector.set(arrows, pattern); String[] testString = new String[3]; testString[0] = "java.awt.Component"; testString[1] = "javax.swing.JComponent"; testString[2] = "java.awt.Container"; DesignParser.makeUML(testString); assertEquals(true, detect.isDetected()); }
@Test public void testaddFieldDescObject() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); Field whitelist = WorkerForArrows.class.getDeclaredField("whitelist"); whitelist.setAccessible(true); ArrayList<String> whitelistv1 = new ArrayList<String>(Arrays.asList("java_lang_Object")); whitelist.set(arrows, whitelistv1); Field fields = UMLArrows.class.getDeclaredField("fields"); fields.setAccessible(true); ArrayList<String> fieldsarray = new ArrayList<String>(); fields.set(arrows, new ArrayList<String>()); // We must avoid having the stripper from touching this string String toAdd = "java_lang_Object"; String desc = "Ljava/lang/Object;"; int access = Opcodes.ACC_PUBLIC; fieldsarray.add(toAdd); arrows.addFieldDesc(desc, access); assertEquals(fieldsarray, fields.get(arrows)); }
@Test public void testresetUMLArrowsValues() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { UMLArrows arrows = UMLArrows.getInstance(); // Get the fields // //Whitelist is not reset in Reset Arrows, since it is consistent // //between all class in UML // Field whitelist = // WorkerForArrows.class.getDeclaredField("whitelist"); // whitelist.setAccessible(true); Field supers = UMLArrows.class.getDeclaredField("supers"); supers.setAccessible(true); Field interfaces = UMLArrows.class.getDeclaredField("interfaces"); interfaces.setAccessible(true); Field uses = UMLArrows.class.getDeclaredField("uses"); uses.setAccessible(true); Field fields = UMLArrows.class.getDeclaredField("fields"); fields.setAccessible(true); // Set the values // whitelist.set(arrows,new ArrayList<String>(Arrays.asList( // "String", "cóol", "Understood"))); supers.set(arrows, "This is a cool String"); interfaces.set( arrows, new ArrayList<String>(Arrays.asList("Looks interesting", "cóol", "Understood"))); uses.set(arrows, new ArrayList<String>(Arrays.asList("String", "cóol", "Testing123"))); fields.set(arrows, new ArrayList<String>(Arrays.asList("Helllllo", "cóol", "Mic Check?"))); // Reset arrows.resetUMLArrows(); // Test // assertEquals(whitelist.get(arrows), new ArrayList<String>()); assertEquals("", supers.get(arrows)); assertEquals(new ArrayList<String>(), interfaces.get(arrows)); assertEquals(new ArrayList<String>(), uses.get(arrows)); assertEquals(new ArrayList<String>(), fields.get(arrows)); }
@Test public void testgetInstance() { assertEquals("UMLArrows", (UMLArrows.getInstance().getClass().getSimpleName())); }
@Test public void testgetSameInstance() { UMLArrows arrows = UMLArrows.getInstance(); // == used to test if it is the same Instance. assertTrue(arrows == UMLArrows.getInstance()); }