FileDocCategorySizeDatePackage
JUnitTestCaseAdapter.javaAPI DocAndroid 1.5 API16041Wed May 06 22:41:04 BST 2009org.w3c.domts

JUnitTestCaseAdapter

public class JUnitTestCaseAdapter extends TestCase implements DOMTestFramework

Fields Summary
private DOMTestCase
test
private static DOMTestDocumentBuilderFactory
defaultFactory
private String
errorMessage
private boolean
failed
Constructors Summary
public JUnitTestCaseAdapter(DOMTestCase test)

 

     
    super(test.getTargetURI());
    test.setFramework(this);
    this.test = test;
  
public JUnitTestCaseAdapter()

      
  
Methods Summary
public voidassertEquals(DOMTestCase test, java.lang.String assertID, java.lang.String expected, java.lang.String actual)

    assertEquals(assertID,expected,actual);
  
public voidassertEquals(DOMTestCase test, java.lang.String assertID, int expected, int actual)

    assertEquals(assertID,expected,actual);
  
public voidassertEquals(DOMTestCase test, java.lang.String assertID, boolean expected, boolean actual)

    assertEquals(assertID,expected,actual);
  
public voidassertEquals(DOMTestCase test, java.lang.String assertID, double expected, double actual)

      assertEquals(assertID, expected, actual, 0.0);
  
public voidassertEquals(DOMTestCase test, java.lang.String assertID, java.util.Collection expected, java.util.Collection actual)

    int size = expected.size();
    assertNotNull(assertID,expected);
    assertNotNull(assertID,actual);
    assertEquals(assertID,size, actual.size());
    boolean equals = (expected != null && actual != null && size == actual.size());
    if(equals) {
      List expectedArray = new ArrayList(expected);
      Object expectedObj;
      Object actualObj;
      Iterator actualIter = actual.iterator();
      Iterator expectedIter;
      while(actualIter.hasNext() && equals) {
        actualObj = actualIter.next();
        expectedIter = expectedArray.iterator();
        equals = false;
        while(expectedIter.hasNext() && !equals) {
          expectedObj = expectedIter.next();
          if(expectedObj == actualObj || expectedObj.equals(actualObj)) {
            equals = true;
            expectedArray.remove(expectedObj);
          }
        }
      }
    }
    assertTrue(assertID,equals);
  
public voidassertEqualsIgnoreCase(DOMTestCase test, java.lang.String assertID, java.lang.String expected, java.lang.String actual)

  	if (!expected.equalsIgnoreCase(actual)) {
  		assertEquals(assertID,expected, actual);
  	}
  
public voidassertEqualsIgnoreCase(DOMTestCase test, java.lang.String assertID, java.util.Collection expected, java.util.Collection actual)

    int size = expected.size();
    assertNotNull(assertID,expected);
    assertNotNull(assertID,actual);
    assertEquals(assertID,size, actual.size());
    boolean equals = (expected != null && actual != null && size == actual.size());
    if(equals) {
      List expectedArray = new ArrayList(expected);
      String expectedString;
      String actualString;
      Iterator actualIter = actual.iterator();
      Iterator expectedIter;
      while(actualIter.hasNext() && equals) {
        actualString = (String) actualIter.next();
        expectedIter = expectedArray.iterator();
        equals = false;
        while(expectedIter.hasNext() && !equals) {
          expectedString = (String) expectedIter.next();
          if(actualString.equalsIgnoreCase(expectedString)) {
            equals = true;
            expectedArray.remove(expectedString);
          }
        }
      }
    }
    assertTrue(assertID,equals);
  
public voidassertEqualsIgnoreCase(DOMTestCase test, java.lang.String assertID, java.util.List expected, java.util.List actual)

    int size = expected.size();
    assertNotNull(assertID,expected);
    assertNotNull(assertID,actual);
    assertEquals(assertID,size, actual.size());
    boolean equals = (expected != null && actual != null && size == actual.size());
    if(equals) {
      String expectedString;
      String actualString;
      for(int i = 0; i < size; i++) {
        expectedString = (String) expected.get(i);
        actualString = (String) actual.get(i);
        if(!expectedString.equalsIgnoreCase(actualString)) {
          assertEquals(assertID,expectedString,actualString);
          break;
        }
      }
    }
  
public voidassertFalse(DOMTestCase test, java.lang.String assertID, boolean actual)

    if(actual) {
      assertEquals(assertID,String.valueOf(false), String.valueOf(actual));
    }
  
public voidassertInstanceOf(DOMTestCase test, java.lang.String assertID, java.lang.Object obj, java.lang.Class cls)

    assertTrue(assertID,cls.isInstance(obj));
  
public voidassertNotEquals(DOMTestCase test, java.lang.String assertID, java.lang.String expected, java.lang.String actual)

    assertTrue(assertID, !expected.equals(actual));
  
public voidassertNotEquals(DOMTestCase test, java.lang.String assertID, int expected, int actual)

    assertTrue(assertID,expected !=actual);
  
public voidassertNotEquals(DOMTestCase test, java.lang.String assertID, boolean expected, boolean actual)

    assertTrue(assertID,expected !=actual);
  
public voidassertNotEquals(DOMTestCase test, java.lang.String assertID, double expected, double actual)

    if(expected == actual) {
      assertTrue(assertID,expected != actual);
    }
  
public voidassertNotEqualsIgnoreCase(DOMTestCase test, java.lang.String assertID, java.lang.String expected, java.lang.String actual)

    if(expected.equalsIgnoreCase(actual)) {
      assertTrue(assertID, !expected.equalsIgnoreCase(actual));
    }
  
public voidassertNotNull(DOMTestCase test, java.lang.String assertID, java.lang.Object actual)

    assertNotNull(assertID,actual);
  
public voidassertNull(DOMTestCase test, java.lang.String assertID, java.lang.Object actual)

    assertNull(assertID,actual);
  
public voidassertSame(DOMTestCase test, java.lang.String assertID, java.lang.Object expected, java.lang.Object actual)

    boolean same = (expected == actual);
    //
    //   if the not the same but both are not null
    //      might still really be the same
    //
    if(!same) {
      if(expected == null || actual == null ||
         !(expected instanceof Node) || !(actual instanceof Node)) {
        assertEquals(assertID,expected,actual);
      }
      else {
        //
        //  could do something with isSame
        //
        assertEquals(assertID,expected,actual);
      }
    }
  
public voidassertSize(DOMTestCase test, java.lang.String assertID, int expectedSize, org.w3c.dom.NodeList collection)

    assertEquals(assertID,expectedSize, collection.getLength());
  
public voidassertSize(DOMTestCase test, java.lang.String assertID, int expectedSize, org.w3c.dom.NamedNodeMap collection)

    assertEquals(assertID, expectedSize, collection.getLength());
  
public voidassertSize(DOMTestCase test, java.lang.String assertID, int expectedSize, java.util.Collection collection)

    assertEquals(assertID, expectedSize, collection.size());
  
public voidassertTrue(DOMTestCase test, java.lang.String assertID, boolean actual)

    assertTrue(assertID,actual);
  
public booleanequals(java.lang.String expected, java.lang.String actual)

    return expected.equals(actual);
  
public booleanequals(int expected, int actual)

    return expected == actual;
  
public booleanequals(boolean expected, boolean actual)

    return expected == actual;
  
public booleanequals(double expected, double actual)

    return expected == actual;
  
public booleanequals(java.util.Collection expected, java.util.Collection actual)

    int size = expected.size();
    boolean equals = (expected != null && actual != null && size == actual.size());
    if(equals) {
      List expectedArray = new ArrayList(expected);
      Object expectedObj;
      Object actualObj;
      Iterator actualIter = actual.iterator();
      Iterator expectedIter;
      while(actualIter.hasNext() && equals) {
        actualObj = actualIter.next();
        expectedIter = expectedArray.iterator();
        equals = false;
        while(expectedIter.hasNext() && !equals) {
          expectedObj = expectedIter.next();
          if(expectedObj != actualObj && expectedObj.equals(actualObj)) {
            equals = true;
            expectedArray.remove(expectedObj);
          }
        }
      }
    }
    return equals;
  
public booleanequals(java.util.List expected, java.util.List actual)

    int size = expected.size();
    boolean equals = (expected != null && actual != null && size == actual.size());
    if(equals) {
      Object expectedObj;
      Object actualObj;
      for(int i = 0; i < size; i++) {
        expectedObj = expected.get(i);
        actualObj = actual.get(i);
        if(!expectedObj.equals(actualObj)) {
          equals = false;
          break;
        }
      }
    }
    return equals;
  
public booleanequalsIgnoreCase(java.lang.String expected, java.lang.String actual)

    return expected.equalsIgnoreCase(actual);
  
public booleanequalsIgnoreCase(java.util.Collection expected, java.util.Collection actual)

    int size = expected.size();
    boolean equals = (expected != null && actual != null && size == actual.size());
    if(equals) {
      List expectedArray = new ArrayList(expected);
      String expectedString;
      String actualString;
      Iterator actualIter = actual.iterator();
      Iterator expectedIter;
      while(actualIter.hasNext() && equals) {
        actualString = (String) actualIter.next();
        expectedIter = expectedArray.iterator();
        equals = false;
        while(expectedIter.hasNext() && !equals) {
          expectedString = (String) expectedIter.next();
          if(actualString.equalsIgnoreCase(expectedString)) {
            equals = true;
            expectedArray.remove(expectedString);
          }
        }
      }
    }
    return equals;
  
public booleanequalsIgnoreCase(java.util.List expected, java.util.List actual)

    int size = expected.size();
    boolean equals = (expected != null && actual != null && size == actual.size());
    if(equals) {
      String expectedString;
      String actualString;
      for(int i = 0; i < size; i++) {
        expectedString = (String) expected.get(i);
        actualString = (String) actual.get(i);
        if(!expectedString.equalsIgnoreCase(actualString)) {
          equals = false;
          break;
        }
      }
    }
    return equals;
  
public voidfail(DOMTestCase test, java.lang.String assertID)

  	fail(assertID);
  
public booleanhasFeature(javax.xml.parsers.DocumentBuilder docBuilder, java.lang.String feature, java.lang.String version)

     return docBuilder.getDOMImplementation().hasFeature(feature,version);
  
protected voidrunTest()

      //BEGIN android-added
      if (failed) {
          if (errorMessage != null) {
              fail(errorMessage);
          } else {
              fail("init failed");
          }
      }
      //END android-added
    test.runTest();
    int mutationCount = test.getMutationCount();
    if (mutationCount != 0) {
    	fail("Document loaded with willBeModified='false' was modified in course of test.");
    }
  
public booleansame(java.lang.Object expected, java.lang.Object actual)

    boolean equals = (expected == actual);
    if(!equals && expected != null && expected instanceof Node &&
      actual != null && actual instanceof Node) {
      //
      //  can use Node.isSame eventually
    }
    return equals;
  
public voidsetName(java.lang.String name)

  
  
        
        super.setName(name);
        if (test == null) {
            try {
                URI uri = new URI(name);
                String path = uri.getPath();
                path = path.replaceAll("/", ".");
                Class<?> clazz = null;
                int pos = path.indexOf('.");
                while (pos != -1) {
                    try {
                        clazz = Class.forName("org.w3c.domts." + path);
                        break;
                    } catch (ClassNotFoundException e) {
                        // do nothing
                    }
                    path = path.substring(pos + 1);
                }
                if (clazz == null) {
                    errorMessage = "class not found for test: " + name;
                    failed = true;
                    return;
                }

                if (defaultFactory == null) {
                    defaultFactory = new JAXPDOMTestDocumentBuilderFactory(null,
                            JAXPDOMTestDocumentBuilderFactory.getConfiguration1());
                }

                Constructor<?> constructor = clazz.getConstructor(new Class<?>[] {
                    DOMTestDocumentBuilderFactory.class
                });

                test = (DOMTestCase)constructor.newInstance(new Object[] {
                    defaultFactory
                });
                test.setFramework(this);
                
            } catch (URISyntaxException e) {
                failed = true;
                errorMessage = e.getMessage();
                if (errorMessage == null) {
                    errorMessage = "" + e.toString();
                }
            } catch (IllegalAccessException e) {
                failed = true;
                errorMessage = e.getMessage();
                if (errorMessage == null) {
                    errorMessage = "" + e.toString();
                }
            } catch (InstantiationException e) {
                failed = true;
                errorMessage = e.getMessage();
                if (errorMessage == null) {
                    errorMessage = "" + e.toString();
                }
            } catch (DOMTestIncompatibleException e) {
                failed = true;
                errorMessage = e.getMessage();
                if (errorMessage == null) {
                    errorMessage = "" + e.toString();
                }
            } catch (SecurityException e) {
                failed = true;
                errorMessage = e.getMessage();
                if (errorMessage == null) {
                    errorMessage = "" + e.toString();
                }
            } catch (NoSuchMethodException e) {
                failed = true;
                errorMessage = e.getMessage();
                if (errorMessage == null) {
                    errorMessage = "" + e.toString();
                }
            } catch (IllegalArgumentException e) {
                failed = true;
                errorMessage = e.getMessage();
                if (errorMessage == null) {
                    errorMessage = "" + e.toString();
                }
            } catch (InvocationTargetException e) {
                failed = true;
                Throwable t = e.getCause();
                if (t != null) {
                    errorMessage = t.getMessage();
                    if (errorMessage == null) {
                        errorMessage = "" + t.toString();
                    }
                } else {
                    errorMessage = e.getMessage();
                    if (errorMessage == null) {
                        errorMessage = "" + e.toString();
                    }
                }
            }
        }
    
public intsize(java.util.Collection collection)

    return collection.size();
  
public intsize(org.w3c.dom.NamedNodeMap collection)

    return collection.getLength();
  
public intsize(org.w3c.dom.NodeList collection)

    return collection.getLength();
  
public voidwait(int millisecond)