Ejemplo n.º 1
0
  @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());
  }
Ejemplo n.º 2
0
 @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));
 }