1 6 7 package com.hp.hpl.jena.test; 8 9 import java.lang.reflect.*; 10 import junit.framework.*; 11 import java.util.*; 12 13 import com.hp.hpl.jena.util.CollectionFactory; 14 15 22 public class JenaTestBase extends TestCase 23 { 24 public JenaTestBase( String name ) 25 { super( name ); } 26 27 33 public static void assertDiffer( String title, Object x, Object y ) 34 { 35 if (x == null ? y == null : x.equals( y )) 36 fail( (title == null ? "objects should be different, but both were: " : title) + x ); 37 } 38 39 44 public static void assertDiffer( Object x, Object y ) 45 { assertDiffer( null, x, y ); } 46 47 50 public static Set listToSet( List L ) 51 { return CollectionFactory.createHashedSet( L ); } 52 53 57 public static void pass() 58 {} 59 60 64 public static Constructor getConstructor( Class c, Class [] args ) 65 { 66 try { return c.getConstructor( args ); } 67 catch (NoSuchMethodException e) { return null; } 68 } 69 70 74 public static boolean isPublicTestMethod( Method m ) 75 { return Modifier.isPublic( m.getModifiers() ) && isTestMethod( m ); } 76 77 81 public static boolean isTestMethod( Method m ) 82 { return 83 m.getName().startsWith( "test" ) 84 && m.getParameterTypes().length == 0 85 && m.getReturnType().equals( Void.TYPE ); } 86 87 92 public boolean hasAsParent( Class subClass, Class superClass ) 93 { 94 if (subClass == superClass || subClass.getSuperclass() == superClass) return true; 95 Class [] is = subClass.getInterfaces(); 96 for (int i = 0; i < is.length; i += 1) if (hasAsParent( is[i], superClass )) return true; 97 return false; 98 } 99 100 104 public void assertHasParent( Class subClass, Class superClass ) 105 { 106 if (hasAsParent( subClass, superClass ) == false) 107 fail( "" + subClass + " should have " + superClass + " as a parent" ); 108 } 109 110 public List append(List L, List R) 111 { List result = new ArrayList( L ); 112 result.addAll( R ); 113 return result; } 114 115 } 116 117 118 | Popular Tags |