dx

16:35:28.385 INFO  jd.cli.Main - Decompiling dx.jar
package junit.extensions;

import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestResult;

public class TestDecorator
  extends Assert
  implements Test
{
  protected Test fTest;
  
  public TestDecorator(Test test)
  {
    fTest = test;
  }
  
  public void basicRun(TestResult result)
  {
    fTest.run(result);
  }
  
  public int countTestCases()
  {
    return fTest.countTestCases();
  }
  
  public void run(TestResult result)
  {
    basicRun(result);
  }
  
  public String toString()
  {
    return fTest.toString();
  }
  
  public Test getTest()
  {
    return fTest;
  }
}

/* Location:
 * Qualified Name:     junit.extensions.TestDecorator
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.extensions;

import junit.framework.Protectable;
import junit.framework.Test;
import junit.framework.TestResult;

public class TestSetup
  extends TestDecorator
{
  public TestSetup(Test test)
  {
    super(test);
  }
  
  public void run(final TestResult result)
  {
    Protectable p = new Protectable()
    {
      public void protect()
        throws Exception
      {
        setUp();
        basicRun(result);
        tearDown();
      }
    };
    result.runProtected(this, p);
  }
  
  protected void setUp()
    throws Exception
  {}
  
  protected void tearDown()
    throws Exception
  {}
}

/* Location:
 * Qualified Name:     junit.extensions.TestSetup
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.extensions;

import junit.framework.TestCase;

public class ExceptionTestCase
  extends TestCase
{
  Class<?> fExpected;
  
  public ExceptionTestCase(String name, Class exception)
  {
    super(name);
    fExpected = exception;
  }
  
  protected void runTest()
    throws Throwable
  {
    try
    {
      super.runTest();
    }
    catch (Exception e)
    {
      if (fExpected.isAssignableFrom(e.getClass())) {
        return;
      }
      throw e;
    }
    fail("Expected exception " + fExpected);
  }
}

/* Location:
 * Qualified Name:     junit.extensions.ExceptionTestCase
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.extensions;

import junit.framework.Protectable;
import junit.framework.TestResult;

class TestSetup$1
  implements Protectable
{
  TestSetup$1(TestSetup paramTestSetup, TestResult paramTestResult) {}
  
  public void protect()
    throws Exception
  {
    this$0.setUp();
    this$0.basicRun(val$result);
    this$0.tearDown();
  }
}

/* Location:
 * Qualified Name:     junit.extensions.TestSetup.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.extensions;

import junit.framework.Test;
import junit.framework.TestResult;

public class RepeatedTest
  extends TestDecorator
{
  private int fTimesRepeat;
  
  public RepeatedTest(Test test, int repeat)
  {
    super(test);
    if (repeat < 0) {
      throw new IllegalArgumentException("Repetition count must be > 0");
    }
    fTimesRepeat = repeat;
  }
  
  public int countTestCases()
  {
    return super.countTestCases() * fTimesRepeat;
  }
  
  public void run(TestResult result)
  {
    for (int i = 0; i < fTimesRepeat; i++)
    {
      if (result.shouldStop()) {
        break;
      }
      super.run(result);
    }
  }
  
  public String toString()
  {
    return super.toString() + "(repeated)";
  }
}

/* Location:
 * Qualified Name:     junit.extensions.RepeatedTest
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.extensions;

import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;

public class ActiveTestSuite
  extends TestSuite
{
  private volatile int fActiveTestDeathCount;
  
  public ActiveTestSuite() {}
  
  public ActiveTestSuite(Class theClass)
  {
    super(theClass);
  }
  
  public ActiveTestSuite(String name)
  {
    super(name);
  }
  
  public ActiveTestSuite(Class theClass, String name)
  {
    super(theClass, name);
  }
  
  public void run(TestResult result)
  {
    fActiveTestDeathCount = 0;
    super.run(result);
    waitUntilFinished();
  }
  
  public void runTest(final Test test, final TestResult result)
  {
    Thread t = new Thread()
    {
      public void run()
      {
        try
        {
          test.run(result);
        }
        finally
        {
          runFinished(test);
        }
      }
    };
    t.start();
  }
  
  synchronized void waitUntilFinished()
  {
    while (fActiveTestDeathCount < testCount()) {
      try
      {
        wait();
      }
      catch (InterruptedException e) {}
    }
  }
  
  public synchronized void runFinished(Test test)
  {
    fActiveTestDeathCount += 1;
    notifyAll();
  }
}

/* Location:
 * Qualified Name:     junit.extensions.ActiveTestSuite
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.extensions;

import junit.framework.Test;
import junit.framework.TestResult;

class ActiveTestSuite$1
  extends Thread
{
  ActiveTestSuite$1(ActiveTestSuite paramActiveTestSuite, Test paramTest, TestResult paramTestResult) {}
  
  public void run()
  {
    try
    {
      val$test.run(val$result);
    }
    finally
    {
      this$0.runFinished(val$test);
    }
  }
}

/* Location:
 * Qualified Name:     junit.extensions.ActiveTestSuite.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

import java.util.Vector;

public class Sorter
{
  public static void sortStrings(Vector values, int left, int right, Swapper swapper)
  {
    int oleft = left;
    int oright = right;
    String mid = (String)values.elementAt((left + right) / 2);
    do
    {
      while (((String)values.elementAt(left)).compareTo(mid) < 0) {
        left++;
      }
      while (mid.compareTo((String)values.elementAt(right)) < 0) {
        right--;
      }
      if (left <= right)
      {
        swapper.swap(values, left, right);
        left++;
        right--;
      }
    } while (left <= right);
    if (oleft < right) {
      sortStrings(values, oleft, right, swapper);
    }
    if (left < oright) {
      sortStrings(values, left, oright, swapper);
    }
  }
  
  public static abstract interface Swapper
  {
    public abstract void swap(Vector paramVector, int paramInt1, int paramInt2);
  }
}

/* Location:
 * Qualified Name:     junit.runner.Sorter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

import java.awt.Component;
import junit.framework.TestFailure;

public abstract interface FailureDetailView
{
  public abstract Component getComponent();
  
  public abstract void showFailure(TestFailure paramTestFailure);
  
  public abstract void clear();
}

/* Location:
 * Qualified Name:     junit.runner.FailureDetailView
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

public abstract interface TestSuiteLoader
{
  public abstract Class load(String paramString)
    throws ClassNotFoundException;
  
  public abstract Class reload(Class paramClass)
    throws ClassNotFoundException;
}

/* Location:
 * Qualified Name:     junit.runner.TestSuiteLoader
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class TestCaseClassLoader
  extends ClassLoader
{
  private Vector<String> fPathItems;
  private String[] defaultExclusions = { "junit.framework.", "junit.extensions.", "junit.runner." };
  static final String EXCLUDED_FILE = "excluded.properties";
  private Vector<String> fExcluded;
  
  public TestCaseClassLoader()
  {
    this(System.getProperty("java.class.path"));
  }
  
  public TestCaseClassLoader(String classPath)
  {
    scanPath(classPath);
    readExcludedPackages();
  }
  
  private void scanPath(String classPath)
  {
    String separator = System.getProperty("path.separator");
    fPathItems = new Vector(10);
    StringTokenizer st = new StringTokenizer(classPath, separator);
    while (st.hasMoreTokens()) {
      fPathItems.addElement(st.nextToken());
    }
  }
  
  public URL getResource(String name)
  {
    return ClassLoader.getSystemResource(name);
  }
  
  public InputStream getResourceAsStream(String name)
  {
    return ClassLoader.getSystemResourceAsStream(name);
  }
  
  public boolean isExcluded(String name)
  {
    for (int i = 0; i < fExcluded.size(); i++) {
      if (name.startsWith((String)fExcluded.elementAt(i))) {
        return true;
      }
    }
    return false;
  }
  
  public synchronized Class loadClass(String name, boolean resolve)
    throws ClassNotFoundException
  {
    Class c = findLoadedClass(name);
    if (c != null) {
      return c;
    }
    if (isExcluded(name)) {
      try
      {
        return findSystemClass(name);
      }
      catch (ClassNotFoundException e) {}
    }
    if (c == null)
    {
      byte[] data = lookupClassData(name);
      if (data == null) {
        throw new ClassNotFoundException();
      }
      c = defineClass(name, data, 0, data.length);
    }
    if (resolve) {
      resolveClass(c);
    }
    return c;
  }
  
  private byte[] lookupClassData(String className)
    throws ClassNotFoundException
  {
    byte[] data = null;
    for (int i = 0; i < fPathItems.size(); i++)
    {
      String path = (String)fPathItems.elementAt(i);
      String fileName = className.replace('.', '/') + ".class";
      if (isJar(path)) {
        data = loadJarData(path, fileName);
      } else {
        data = loadFileData(path, fileName);
      }
      if (data != null) {
        return data;
      }
    }
    throw new ClassNotFoundException(className);
  }
  
  boolean isJar(String pathEntry)
  {
    return (pathEntry.endsWith(".jar")) || (pathEntry.endsWith(".zip")) || (pathEntry.endsWith(".apk"));
  }
  
  private byte[] loadFileData(String path, String fileName)
  {
    File file = new File(path, fileName);
    if (file.exists()) {
      return getClassData(file);
    }
    return null;
  }
  
  private byte[] getClassData(File f)
  {
    try
    {
      FileInputStream stream = new FileInputStream(f);
      ByteArrayOutputStream out = new ByteArrayOutputStream(1000);
      byte[] b = new byte['?'];
      int n;
      while ((n = stream.read(b)) != -1) {
        out.write(b, 0, n);
      }
      stream.close();
      out.close();
      return out.toByteArray();
    }
    catch (IOException e) {}
    return null;
  }
  
  private byte[] loadJarData(String path, String fileName)
  {
    ZipFile zipFile = null;
    InputStream stream = null;
    File archive = new File(path);
    if (!archive.exists()) {
      return null;
    }
    try
    {
      zipFile = new ZipFile(archive);
    }
    catch (IOException io)
    {
      return null;
    }
    ZipEntry entry = zipFile.getEntry(fileName);
    if (entry == null) {
      return null;
    }
    int size = (int)entry.getSize();
    try
    {
      stream = zipFile.getInputStream(entry);
      byte[] data = new byte[size];
      int pos = 0;
      int n;
      while (pos < size)
      {
        n = stream.read(data, pos, data.length - pos);
        pos += n;
      }
      zipFile.close();
      return data;
    }
    catch (IOException e) {}finally
    {
      try
      {
        if (stream != null) {
          stream.close();
        }
      }
      catch (IOException e) {}
    }
    return null;
  }
  
  private void readExcludedPackages()
  {
    fExcluded = new Vector(10);
    for (int i = 0; i < defaultExclusions.length; i++) {
      fExcluded.addElement(defaultExclusions[i]);
    }
    InputStream is = getClass().getResourceAsStream("excluded.properties");
    if (is == null) {
      return;
    }
    Properties p = new Properties();
    try
    {
      p.load(is);
      try
      {
        is.close();
      }
      catch (IOException e) {}
      e = p.propertyNames();
    }
    catch (IOException e)
    {
      return;
    }
    finally
    {
      try
      {
        is.close();
      }
      catch (IOException e) {}
    }
    Enumeration e;
    while (e.hasMoreElements())
    {
      String key = (String)e.nextElement();
      if (key.startsWith("excluded."))
      {
        String path = p.getProperty(key);
        path = path.trim();
        if (path.endsWith("*")) {
          path = path.substring(0, path.length() - 1);
        }
        if (path.length() > 0) {
          fExcluded.addElement(path);
        }
      }
    }
  }
}

/* Location:
 * Qualified Name:     junit.runner.TestCaseClassLoader
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

import java.util.Vector;

public abstract interface Sorter$Swapper
{
  public abstract void swap(Vector paramVector, int paramInt1, int paramInt2);
}

/* Location:
 * Qualified Name:     junit.runner.Sorter.Swapper
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

import java.util.Enumeration;

public abstract interface TestCollector
{
  public abstract Enumeration collectTests();
}

/* Location:
 * Qualified Name:     junit.runner.TestCollector
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

public class StandardTestSuiteLoader
  implements TestSuiteLoader
{
  public Class load(String suiteClassName)
    throws ClassNotFoundException
  {
    return Class.forName(suiteClassName);
  }
  
  public Class reload(Class aClass)
    throws ClassNotFoundException
  {
    return aClass;
  }
}

/* Location:
 * Qualified Name:     junit.runner.StandardTestSuiteLoader
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

public class Version
{
  public static String id()
  {
    return "3.8.1";
  }
}

/* Location:
 * Qualified Name:     junit.runner.Version
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

public class ReloadingTestSuiteLoader
  implements TestSuiteLoader
{
  public Class load(String suiteClassName)
    throws ClassNotFoundException
  {
    return createLoader().loadClass(suiteClassName, true);
  }
  
  public Class reload(Class aClass)
    throws ClassNotFoundException
  {
    return createLoader().loadClass(aClass.getName(), true);
  }
  
  protected TestCaseClassLoader createLoader()
  {
    return new TestCaseClassLoader();
  }
}

/* Location:
 * Qualified Name:     junit.runner.ReloadingTestSuiteLoader
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

import java.io.File;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;

public abstract class ClassPathTestCollector
  implements TestCollector
{
  static final int SUFFIX_LENGTH = ".class".length();
  
  public Enumeration collectTests()
  {
    String classPath = System.getProperty("java.class.path");
    Hashtable result = collectFilesInPath(classPath);
    return result.elements();
  }
  
  public Hashtable collectFilesInPath(String classPath)
  {
    Hashtable result = collectFilesInRoots(splitClassPath(classPath));
    return result;
  }
  
  Hashtable collectFilesInRoots(Vector roots)
  {
    Hashtable<String, String> result = new Hashtable(100);
    Enumeration e = roots.elements();
    while (e.hasMoreElements()) {
      gatherFiles(new File((String)e.nextElement()), "", result);
    }
    return result;
  }
  
  void gatherFiles(File classRoot, String classFileName, Hashtable<String, String> result)
  {
    File thisRoot = new File(classRoot, classFileName);
    if (thisRoot.isFile())
    {
      if (isTestClass(classFileName))
      {
        String className = classNameFromFile(classFileName);
        result.put(className, className);
      }
      return;
    }
    String[] contents = thisRoot.list();
    if (contents != null) {
      for (int i = 0; i < contents.length; i++) {
        gatherFiles(classRoot, classFileName + File.separatorChar + contents[i], result);
      }
    }
  }
  
  Vector splitClassPath(String classPath)
  {
    Vector<String> result = new Vector();
    String separator = System.getProperty("path.separator");
    StringTokenizer tokenizer = new StringTokenizer(classPath, separator);
    while (tokenizer.hasMoreTokens()) {
      result.addElement(tokenizer.nextToken());
    }
    return result;
  }
  
  protected boolean isTestClass(String classFileName)
  {
    return (classFileName.endsWith(".class")) && (classFileName.indexOf('$') < 0) && (classFileName.indexOf("Test") > 0);
  }
  
  protected String classNameFromFile(String classFileName)
  {
    String s = classFileName.substring(0, classFileName.length() - SUFFIX_LENGTH);
    String s2 = s.replace(File.separatorChar, '.');
    if (s2.startsWith(".")) {
      return s2.substring(1);
    }
    return s2;
  }
}

/* Location:
 * Qualified Name:     junit.runner.ClassPathTestCollector
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

public abstract interface TestRunListener
{
  public static final int STATUS_ERROR = 1;
  public static final int STATUS_FAILURE = 2;
  
  public abstract void testRunStarted(String paramString, int paramInt);
  
  public abstract void testRunEnded(long paramLong);
  
  public abstract void testRunStopped(long paramLong);
  
  public abstract void testStarted(String paramString);
  
  public abstract void testEnded(String paramString);
  
  public abstract void testFailed(int paramInt, String paramString1, String paramString2);
}

/* Location:
 * Qualified Name:     junit.runner.TestRunListener
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

public class SimpleTestCollector
  extends ClassPathTestCollector
{
  protected boolean isTestClass(String classFileName)
  {
    return (classFileName.endsWith(".class")) && (classFileName.indexOf('$') < 0) && (classFileName.indexOf("Test") > 0);
  }
}

/* Location:
 * Qualified Name:     junit.runner.SimpleTestCollector
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.text.NumberFormat;
import java.util.Properties;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestListener;
import junit.framework.TestSuite;

public abstract class BaseTestRunner
  implements TestListener
{
  static boolean fgFilterStack = true;
  boolean fLoading = true;
  
  public synchronized void startTest(Test test)
  {
    testStarted(test.toString());
  }
  
  protected static void setPreferences(Properties preferences)
  {
    fPreferences = preferences;
  }
  
  protected static Properties getPreferences()
  {
    if (fPreferences == null)
    {
      fPreferences = new Properties();
      fPreferences.put("loading", "true");
      fPreferences.put("filterstack", "true");
      readPreferences();
    }
    return fPreferences;
  }
  
  public static void savePreferences()
    throws IOException
  {
    FileOutputStream fos = new FileOutputStream(getPreferencesFile());
    try
    {
      getPreferences().store(fos, "");
    }
    finally
    {
      fos.close();
    }
  }
  
  public void setPreference(String key, String value)
  {
    getPreferences().setProperty(key, value);
  }
  
  public synchronized void endTest(Test test)
  {
    testEnded(test.toString());
  }
  
  public synchronized void addError(Test test, Throwable t)
  {
    testFailed(1, test, t);
  }
  
  public synchronized void addFailure(Test test, AssertionFailedError t)
  {
    testFailed(2, test, t);
  }
  
  public abstract void testStarted(String paramString);
  
  public abstract void testEnded(String paramString);
  
  public abstract void testFailed(int paramInt, Test paramTest, Throwable paramThrowable);
  
  public Test getTest(String suiteClassName)
  {
    if (suiteClassName.length() <= 0)
    {
      clearStatus();
      return null;
    }
    Class testClass = null;
    try
    {
      testClass = loadSuiteClass(suiteClassName);
    }
    catch (ClassNotFoundException e)
    {
      String clazz = e.getMessage();
      if (clazz == null) {
        clazz = suiteClassName;
      }
      runFailed("Class not found \"" + clazz + "\"");
      return null;
    }
    catch (Exception e)
    {
      runFailed("Error: " + e.toString());
      return null;
    }
    Method suiteMethod = null;
    try
    {
      suiteMethod = testClass.getMethod("suite", new Class[0]);
    }
    catch (Exception e)
    {
      clearStatus();
      return new TestSuite(testClass);
    }
    if (!Modifier.isStatic(suiteMethod.getModifiers()))
    {
      runFailed("Suite() method must be static");
      return null;
    }
    Test test = null;
    try
    {
      test = (Test)suiteMethod.invoke(null, (Object[])new Class[0]);
      if (test == null) {
        return test;
      }
    }
    catch (InvocationTargetException e)
    {
      runFailed("Failed to invoke suite():" + e.getTargetException().toString());
      return null;
    }
    catch (IllegalAccessException e)
    {
      runFailed("Failed to invoke suite():" + e.toString());
      return null;
    }
    clearStatus();
    return test;
  }
  
  public String elapsedTimeAsString(long runTime)
  {
    return NumberFormat.getInstance().format(runTime / 1000.0D);
  }
  
  protected String processArguments(String[] args)
  {
    String suiteName = null;
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-noloading"))
      {
        setLoading(false);
      }
      else if (args[i].equals("-nofilterstack"))
      {
        fgFilterStack = false;
      }
      else if (args[i].equals("-c"))
      {
        if (args.length > i + 1) {
          suiteName = extractClassName(args[(i + 1)]);
        } else {
          System.out.println("Missing Test class name");
        }
        i++;
      }
      else
      {
        suiteName = args[i];
      }
    }
    return suiteName;
  }
  
  public void setLoading(boolean enable)
  {
    fLoading = enable;
  }
  
  public String extractClassName(String className)
  {
    if (className.startsWith("Default package for")) {
      return className.substring(className.lastIndexOf(".") + 1);
    }
    return className;
  }
  
  public static String truncate(String s)
  {
    if ((fgMaxMessageLength != -1) && (s.length() > fgMaxMessageLength)) {
      s = s.substring(0, fgMaxMessageLength) + "...";
    }
    return s;
  }
  
  protected abstract void runFailed(String paramString);
  
  protected Class loadSuiteClass(String suiteClassName)
    throws ClassNotFoundException
  {
    return getLoader().load(suiteClassName);
  }
  
  protected void clearStatus() {}
  
  public TestSuiteLoader getLoader()
  {
    if (useReloadingTestSuiteLoader()) {
      return new ReloadingTestSuiteLoader();
    }
    return new StandardTestSuiteLoader();
  }
  
  protected boolean useReloadingTestSuiteLoader()
  {
    return (getPreference("loading").equals("true")) && (!inVAJava()) && (fLoading);
  }
  
  private static File getPreferencesFile()
  {
    String home = System.getProperty("user.home");
    return new File(home, "junit.properties");
  }
  
  private static void readPreferences()
  {
    InputStream is = null;
    try
    {
      is = new FileInputStream(getPreferencesFile());
      setPreferences(new Properties(getPreferences()));
      getPreferences().load(is);
    }
    catch (IOException e)
    {
      try
      {
        if (is != null) {
          is.close();
        }
      }
      catch (IOException e1) {}
    }
  }
  
  public static String getPreference(String key)
  {
    return getPreferences().getProperty(key);
  }
  
  public static int getPreference(String key, int dflt)
  {
    String value = getPreference(key);
    int intValue = dflt;
    if (value == null) {
      return intValue;
    }
    try
    {
      intValue = Integer.parseInt(value);
    }
    catch (NumberFormatException ne) {}
    return intValue;
  }
  
  public static boolean inVAJava()
  {
    try
    {
      Class.forName("com.ibm.uvm.tools.DebugSupport");
    }
    catch (Exception e)
    {
      return false;
    }
    return true;
  }
  
  public static String getFilteredTrace(Throwable t)
  {
    StringWriter stringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(stringWriter);
    t.printStackTrace(writer);
    StringBuffer buffer = stringWriter.getBuffer();
    String trace = buffer.toString();
    return getFilteredTrace(trace);
  }
  
  public static String getFilteredTrace(String stack)
  {
    if (showStackRaw()) {
      return stack;
    }
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    StringReader sr = new StringReader(stack);
    BufferedReader br = new BufferedReader(sr);
    try
    {
      String line;
      while ((line = br.readLine()) != null) {
        if (!filterLine(line)) {
          pw.println(line);
        }
      }
    }
    catch (Exception IOException)
    {
      return stack;
    }
    return sw.toString();
  }
  
  protected static boolean showStackRaw()
  {
    return (!getPreference("filterstack").equals("true")) || (!fgFilterStack);
  }
  
  static boolean filterLine(String line)
  {
    String[] patterns = { "junit.framework.TestCase", "junit.framework.TestResult", "junit.framework.TestSuite", "junit.framework.Assert.", "junit.swingui.TestRunner", "junit.awtui.TestRunner", "junit.textui.TestRunner", "java.lang.reflect.Method.invoke(" };
    for (int i = 0; i < patterns.length; i++) {
      if (line.indexOf(patterns[i]) > 0) {
        return true;
      }
    }
    return false;
  }
  
  static int fgMaxMessageLength = getPreference("maxmessage", fgMaxMessageLength);
  public static final String SUITE_METHODNAME = "suite";
  private static Properties fPreferences;
}

/* Location:
 * Qualified Name:     junit.runner.BaseTestRunner
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.runner;

import java.lang.reflect.Modifier;
import junit.framework.Test;
import junit.framework.TestSuite;

public class LoadingTestCollector
  extends ClassPathTestCollector
{
  TestCaseClassLoader fLoader;
  
  public LoadingTestCollector()
  {
    fLoader = new TestCaseClassLoader();
  }
  
  protected boolean isTestClass(String classFileName)
  {
    try
    {
      if (classFileName.endsWith(".class"))
      {
        Class testClass = classFromFile(classFileName);
        return (testClass != null) && (isTestClass(testClass));
      }
    }
    catch (ClassNotFoundException expected) {}catch (NoClassDefFoundError notFatal) {}
    return false;
  }
  
  Class classFromFile(String classFileName)
    throws ClassNotFoundException
  {
    String className = classNameFromFile(classFileName);
    if (!fLoader.isExcluded(className)) {
      return fLoader.loadClass(className, false);
    }
    return null;
  }
  
  boolean isTestClass(Class testClass)
  {
    if (hasSuiteMethod(testClass)) {
      return true;
    }
    if ((Test.class.isAssignableFrom(testClass)) && (Modifier.isPublic(testClass.getModifiers())) && (hasPublicConstructor(testClass))) {
      return true;
    }
    return false;
  }
  
  boolean hasSuiteMethod(Class testClass)
  {
    try
    {
      testClass.getMethod("suite", new Class[0]);
    }
    catch (Exception e)
    {
      return false;
    }
    return true;
  }
  
  boolean hasPublicConstructor(Class testClass)
  {
    try
    {
      TestSuite.getTestConstructor(testClass);
    }
    catch (NoSuchMethodException e)
    {
      return false;
    }
    return true;
  }
}

/* Location:
 * Qualified Name:     junit.runner.LoadingTestCollector
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.textui;

import java.io.InputStream;
import java.io.PrintStream;
import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.runner.BaseTestRunner;
import junit.runner.StandardTestSuiteLoader;
import junit.runner.TestSuiteLoader;
import junit.runner.Version;

public class TestRunner
  extends BaseTestRunner
{
  private ResultPrinter fPrinter;
  public static final int SUCCESS_EXIT = 0;
  public static final int FAILURE_EXIT = 1;
  public static final int EXCEPTION_EXIT = 2;
  
  public TestRunner()
  {
    this(System.out);
  }
  
  public TestRunner(PrintStream writer)
  {
    this(new ResultPrinter(writer));
  }
  
  public TestRunner(ResultPrinter printer)
  {
    fPrinter = printer;
  }
  
  public static void run(Class testClass)
  {
    run(new TestSuite(testClass));
  }
  
  public static TestResult run(Test test)
  {
    TestRunner runner = new TestRunner();
    return runner.doRun(test);
  }
  
  public static void runAndWait(Test suite)
  {
    TestRunner aTestRunner = new TestRunner();
    aTestRunner.doRun(suite, true);
  }
  
  public TestSuiteLoader getLoader()
  {
    return new StandardTestSuiteLoader();
  }
  
  public void testFailed(int status, Test test, Throwable t) {}
  
  public void testStarted(String testName) {}
  
  public void testEnded(String testName) {}
  
  protected TestResult createTestResult()
  {
    return new TestResult();
  }
  
  public TestResult doRun(Test test)
  {
    return doRun(test, false);
  }
  
  public TestResult doRun(Test suite, boolean wait)
  {
    TestResult result = createTestResult();
    result.addListener(fPrinter);
    long startTime = System.currentTimeMillis();
    suite.run(result);
    long endTime = System.currentTimeMillis();
    long runTime = endTime - startTime;
    fPrinter.print(result, runTime);
    
    pause(wait);
    return result;
  }
  
  protected void pause(boolean wait)
  {
    if (!wait) {
      return;
    }
    fPrinter.printWaitPrompt();
    try
    {
      System.in.read();
    }
    catch (Exception e) {}
  }
  
  public static void main(String[] args)
  {
    TestRunner aTestRunner = new TestRunner();
    try
    {
      TestResult r = aTestRunner.start(args);
      if (!r.wasSuccessful()) {
        System.exit(1);
      }
      System.exit(0);
    }
    catch (Exception e)
    {
      System.err.println(e.getMessage());
      System.exit(2);
    }
  }
  
  protected TestResult start(String[] args)
    throws Exception
  {
    String testCase = "";
    boolean wait = false;
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-wait")) {
        wait = true;
      } else if (args[i].equals("-c")) {
        testCase = extractClassName(args[(++i)]);
      } else if (args[i].equals("-v")) {
        System.err.println("JUnit " + Version.id() + " by Kent Beck and Erich Gamma");
      } else {
        testCase = args[i];
      }
    }
    if (testCase.equals("")) {
      throw new Exception("Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");
    }
    try
    {
      Test suite = getTest(testCase);
      return doRun(suite, wait);
    }
    catch (Exception e)
    {
      throw new Exception("Could not create and run test suite: " + e);
    }
  }
  
  protected void runFailed(String message)
  {
    System.err.println(message);
    System.exit(1);
  }
  
  public void setPrinter(ResultPrinter printer)
  {
    fPrinter = printer;
  }
}

/* Location:
 * Qualified Name:     junit.textui.TestRunner
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.textui;

import java.io.PrintStream;
import java.text.NumberFormat;
import java.util.Enumeration;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestFailure;
import junit.framework.TestListener;
import junit.framework.TestResult;
import junit.runner.BaseTestRunner;

public class ResultPrinter
  implements TestListener
{
  PrintStream fWriter;
  int fColumn = 0;
  
  public ResultPrinter(PrintStream writer)
  {
    fWriter = writer;
  }
  
  synchronized void print(TestResult result, long runTime)
  {
    printHeader(runTime);
    printErrors(result);
    printFailures(result);
    printFooter(result);
  }
  
  void printWaitPrompt()
  {
    getWriter().println();
    getWriter().println("<RETURN> to continue");
  }
  
  protected void printHeader(long runTime)
  {
    getWriter().println();
    getWriter().println("Time: " + elapsedTimeAsString(runTime));
  }
  
  protected void printErrors(TestResult result)
  {
    printDefects(result.errors(), result.errorCount(), "error");
  }
  
  protected void printFailures(TestResult result)
  {
    printDefects(result.failures(), result.failureCount(), "failure");
  }
  
  protected void printDefects(Enumeration booBoos, int count, String type)
  {
    if (count == 0) {
      return;
    }
    if (count == 1) {
      getWriter().println("There was " + count + " " + type + ":");
    } else {
      getWriter().println("There were " + count + " " + type + "s:");
    }
    for (int i = 1; booBoos.hasMoreElements(); i++) {
      printDefect((TestFailure)booBoos.nextElement(), i);
    }
  }
  
  public void printDefect(TestFailure booBoo, int count)
  {
    printDefectHeader(booBoo, count);
    printDefectTrace(booBoo);
  }
  
  protected void printDefectHeader(TestFailure booBoo, int count)
  {
    getWriter().print(count + ") " + booBoo.failedTest());
  }
  
  protected void printDefectTrace(TestFailure booBoo)
  {
    getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));
  }
  
  protected void printFooter(TestResult result)
  {
    if (result.wasSuccessful())
    {
      getWriter().println();
      getWriter().print("OK");
      getWriter().println(" (" + result.runCount() + " test" + (result.runCount() == 1 ? "" : "s") + ")");
    }
    else
    {
      getWriter().println();
      getWriter().println("FAILURES!!!");
      getWriter().println("Tests run: " + result.runCount() + ",  Failures: " + result.failureCount() + ",  Errors: " + result.errorCount());
    }
    getWriter().println();
  }
  
  protected String elapsedTimeAsString(long runTime)
  {
    return NumberFormat.getInstance().format(runTime / 1000.0D);
  }
  
  public PrintStream getWriter()
  {
    return fWriter;
  }
  
  public void addError(Test test, Throwable t)
  {
    getWriter().print("E");
  }
  
  public void addFailure(Test test, AssertionFailedError t)
  {
    getWriter().print("F");
  }
  
  public void endTest(Test test) {}
  
  public void startTest(Test test)
  {
    getWriter().print(".");
    if (fColumn++ >= 40)
    {
      getWriter().println();
      fColumn = 0;
    }
  }
}

/* Location:
 * Qualified Name:     junit.textui.ResultPrinter
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.framework;

final class TestSuite$1
  extends TestCase
{
  TestSuite$1(String x0, String paramString1)
  {
    super(x0);
  }
  
  protected void runTest()
  {
    fail(val$message);
  }
}

/* Location:
 * Qualified Name:     junit.framework.TestSuite.1
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.framework;

import java.util.Enumeration;
import java.util.Vector;

public class TestResult
{
  protected Vector<TestFailure> fFailures;
  protected Vector<TestFailure> fErrors;
  protected Vector<TestListener> fListeners;
  protected int fRunTests;
  private boolean fStop;
  
  public TestResult()
  {
    fFailures = new Vector();
    fErrors = new Vector();
    fListeners = new Vector();
    fRunTests = 0;
    fStop = false;
  }
  
  public synchronized void addError(Test test, Throwable t)
  {
    fErrors.addElement(new TestFailure(test, t));
    for (Enumeration e = cloneListeners().elements(); e.hasMoreElements();) {
      ((TestListener)e.nextElement()).addError(test, t);
    }
  }
  
  public synchronized void addFailure(Test test, AssertionFailedError t)
  {
    fFailures.addElement(new TestFailure(test, t));
    for (Enumeration e = cloneListeners().elements(); e.hasMoreElements();) {
      ((TestListener)e.nextElement()).addFailure(test, t);
    }
  }
  
  public synchronized void addListener(TestListener listener)
  {
    fListeners.addElement(listener);
  }
  
  public synchronized void removeListener(TestListener listener)
  {
    fListeners.removeElement(listener);
  }
  
  private synchronized Vector cloneListeners()
  {
    return (Vector)fListeners.clone();
  }
  
  public void endTest(Test test)
  {
    for (Enumeration e = cloneListeners().elements(); e.hasMoreElements();) {
      ((TestListener)e.nextElement()).endTest(test);
    }
  }
  
  public synchronized int errorCount()
  {
    return fErrors.size();
  }
  
  public synchronized Enumeration errors()
  {
    return fErrors.elements();
  }
  
  public synchronized int failureCount()
  {
    return fFailures.size();
  }
  
  public synchronized Enumeration failures()
  {
    return fFailures.elements();
  }
  
  protected void run(final TestCase test)
  {
    startTest(test);
    Protectable p = new Protectable()
    {
      public void protect()
        throws Throwable
      {
        test.runBare();
      }
    };
    runProtected(test, p);
    
    endTest(test);
  }
  
  public synchronized int runCount()
  {
    return fRunTests;
  }
  
  public void runProtected(Test test, Protectable p)
  {
    try
    {
      p.protect();
    }
    catch (AssertionFailedError e)
    {
      addFailure(test, e);
    }
    catch (ThreadDeath e)
    {
      throw e;
    }
    catch (Throwable e)
    {
      addError(test, e);
    }
  }
  
  public synchronized boolean shouldStop()
  {
    return fStop;
  }
  
  public void startTest(Test test)
  {
    int count = test.countTestCases();
    synchronized (this)
    {
      fRunTests += count;
    }
    for (Enumeration e = cloneListeners().elements(); e.hasMoreElements();) {
      ((TestListener)e.nextElement()).startTest(test);
    }
  }
  
  public synchronized void stop()
  {
    fStop = true;
  }
  
  public synchronized boolean wasSuccessful()
  {
    return (failureCount() == 0) && (errorCount() == 0);
  }
}

/* Location:
 * Qualified Name:     junit.framework.TestResult
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package junit.framework;

public class Assert
{
  public static void assertTrue(String message, boolean condition)
  {
    if (!condition) {
      fail(message);
    }
  }
  
  public static void assertTrue(boolean condition)
  {
    assertTrue(null, condition);
  }
  
  public static void assertFalse(String message, boolean condition)
  {
    assertTrue(message, !condition);
  }
  
  public static void assertFalse(boolean condition)
  {
    assertFalse(null, condition);
  }
  
  public static void fail(String message)
  {
    throw new AssertionFailedError(message);
  }
  
  public static void fail()
  {
    fail(null);
  }
  
  public static void assertEquals(String message, Object expected, Object actual)
  {
    if ((expected == null) && (actual == null)) {
      return;
    }
    if ((expected != null) && (expected.equals(actual))) {
      return;
    }
    failNotEquals(message, expected, actual);
  }
  
  public static void assertEquals(Object expected, Object actual)
  {
    assertEquals(null, expected, actual);
  }
  
  public static void assertEquals(String message, String expected, String actual)
  {
    if ((expected == null) && (actual == null)) {
      return;
    }
    if ((expected != null) && (ex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd