1 19 24 25 package org.netbeans.jmi.javamodel.usages; 26 27 import java.io.*; 28 import java.util.*; 29 import junit.framework.AssertionFailedError; 30 import org.netbeans.jmi.javamodel.MultipartId; 31 import org.netbeans.junit.AssertionFailedErrorException; 32 33 37 public class FindUtils { 38 39 public static Collection getImmediateComposites(Collection col) { 40 List l = new ArrayList(); 41 42 Iterator i = col.iterator(); 43 44 while (i.hasNext()) { 45 l.add(((MultipartId)i.next()).refImmediateComposite()); 46 } 47 return l; 48 } 49 50 public static void compare(Collection col, String [] classNames, PrintStream log) { 51 52 col = getImmediateComposites(col); 53 54 Collections.sort((List) col, new Comparator() { 55 public int compare(Object o1, Object o2) { 56 return ((Comparable ) o1.getClass().getName()).compareTo(o2.getClass().getName()); 57 } 58 }); 59 60 log.println("Expected number of usages: " + classNames.length); 61 log.println("Total usages found: " + col.size()); 62 log.println("\nExpected usage \tFound usage"); 63 log.println("======================================================"); 64 boolean passed=true; 65 int i=0; 66 try { 67 for (Iterator it = col.iterator(); it.hasNext() && i<classNames.length; i++) { 68 Object o = it.next(); 69 if (! Class.forName("org.netbeans.jmi.javamodel." + classNames[i]).isInstance(o)) { 70 passed = false; 71 } 72 log.println("MultipartId in " + classNames[i] + "\t Multipartid in " + o.getClass().getName()); 73 } 74 if (i != classNames.length) { 75 passed = false; 76 } 77 } catch (ClassNotFoundException ex) { 78 throw new AssertionFailedErrorException(ex); 79 } 80 if (!passed) { 81 throw new AssertionFailedError("Test failed, see log file for details"); 82 } 83 } 84 } 85 86 87 | Popular Tags |