private Set<String> findDuplicateDependencies(List<Dependency> modelDependencies) {
    List<String> modelDependencies2 = new ArrayList<String>();
    for (Dependency dep : modelDependencies) {
      modelDependencies2.add(dep.getManagementKey());
    }

    return new HashSet<String>(
        CollectionUtils.disjunction(modelDependencies2, new HashSet<String>(modelDependencies2)));
  }
Example #2
0
  public void testTrieStructure() {

    List<String> nextCharacterList = new LinkedList<String>();
    nextCharacterList.addAll(trie.getNextNodeCharacterSet());

    Collections.sort(nextCharacterList);

    for (String c : nextCharacterList) {

      List<Method> wordList = trie.getWordList(c);

      List<Method> indexedList = builder.getListForFirstCharacter(c);

      Collections.sort(wordList, methodComparator);
      Collections.sort(indexedList, methodComparator);

      for (int i = 0; i < wordList.size(); i++) {

        Method found = wordList.get(i);
        Method indexed = wordList.get(i);

        String foundString = found.toString();
        String indexedString = indexed.toString();

        if (!foundString.equals(indexedString)) {
          System.out.println("found = " + found.toString());
          System.out.println("as indexed = " + indexed.toString());
        }

        assertEquals(found.toString(), indexed.toString());
      }

      for (int i = wordList.size(); i < indexedList.size(); i++) {

        System.out.println("found = NONE");
        System.out.println("as indexed = " + indexedList.get(i).toString());
      }

      // get the list of elements that are not in the union of the two lists
      @SuppressWarnings("unchecked")
      Collection<Method> disjunctionList = CollectionUtils.disjunction(wordList, indexedList);

      for (Method method : disjunctionList) {

        System.out.println("missing = " + method.toString());
      }

      assertEquals(wordList.size(), indexedList.size());
    }
  }
Example #3
0
  public static void compareObjectsViaFields(Object orig, Object copy, String... skipFields) {
    Class<?> origClass = orig.getClass();
    assertEquals(
        "copy is not an instance of " + origClass + " (" + copy.getClass().getSimpleName() + ")",
        origClass,
        copy.getClass());
    for (Field field : orig.getClass().getDeclaredFields()) {
      try {
        field.setAccessible(true);
        Object origFieldVal = field.get(orig);
        Object copyFieldVal = field.get(copy);
        String fieldName = field.getName();

        boolean skip = false;
        for (String skipFieldName : skipFields) {
          if (skipFieldName.matches(fieldName)) {
            skip = true;
            break;
          }
        }
        if (skip) {
          continue;
        }

        boolean nullFound = false;
        if (origFieldVal == null || copyFieldVal == null) {
          nullFound = true;
          for (String nullFieldName : skipFields) {
            if (nullFieldName.matches(fieldName)) {
              nullFound = false;
            }
          }
        }
        String failMsg = origClass.getSimpleName() + "." + field.getName() + " is null";
        assertFalse(failMsg + "!", nullFound);

        if (copyFieldVal != origFieldVal) {
          assertNotNull(failMsg + "in copy!", copyFieldVal);
          assertNotNull(failMsg + "in original!", origFieldVal);
          Package pkg = origFieldVal.getClass().getPackage();
          if (pkg == null || pkg.getName().startsWith("java.")) {
            if (origFieldVal.getClass().isArray()) {
              if (origFieldVal instanceof byte[]) {
                assertArrayEquals(
                    origClass.getSimpleName() + "." + field.getName(),
                    (byte[]) origFieldVal,
                    (byte[]) copyFieldVal);
              }
            } else if (origFieldVal instanceof Map<?, ?> && copyFieldVal instanceof Map<?, ?>) {
              CollectionUtils.disjunction(
                  ((Map) origFieldVal).values(), ((Map) copyFieldVal).values());
            } else {
              assertEquals(
                  origClass.getSimpleName() + "." + field.getName(), origFieldVal, copyFieldVal);
            }
          } else {
            compareObjectsViaFields(origFieldVal, copyFieldVal, skipFields);
          }
        }
      } catch (Exception e) {
        throw new RuntimeException(
            "Unable to access "
                + field.getName()
                + " when testing "
                + origClass.getSimpleName()
                + ".",
            e);
      }
    }
  }