PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/test/java/com/google/test/metric/JavaClassRepositoryTest.java

http://testability-explorer.googlecode.com/
Java | 68 lines | 46 code | 11 blank | 11 comment | 0 complexity | f5ca67aaa6cec0a52b32b8f828eca233 MD5 | raw file
 1package com.google.test.metric;
 2
 3import java.util.Map;
 4
 5import junit.framework.TestCase;
 6
 7import com.google.classpath.ClassPath;
 8import com.google.classpath.ClassPathFactory;
 9
10/**
11 * Tests for the JavaClassRepository
12 * @author alexeagle@google.com (Alex Eagle)
13 */
14public class JavaClassRepositoryTest extends TestCase {
15
16  ClassPath cp = new ClassPathFactory().createFromJVM();
17  ClassRepository repository = new JavaClassRepository(cp);
18
19  /**
20   * This  is a regression test without an assert. The failure condition we are
21   * testing for is that the method call takes forever (high polynomial time)
22   * in revision 180 and before. So we just want to be sure this test runs
23   * in a reasonable amount of time.
24   * @throws Exception
25   */
26  public void testParseFinishes() throws Exception {
27    repository.getClass(DeeplyNestedIfStatements.class.getCanonicalName());
28    assertTrue(true);
29  }
30
31  private static class DeeplyNestedIfStatements {
32    @SuppressWarnings("unused")
33	private static void nested(boolean x) {
34        int num =
35          (x ? 1 : 0) +
36          (x ? 1 : 0) +
37          (x ? 1 : 0) +
38          (x ? 1 : 0) +
39          (x ? 1 : 0) +
40          (x ? 1 : 0) +
41          (x ? 1 : 0) +
42          (x ? 1 : 0) +
43          (x ? 1 : 0) +
44          (x ? 1 : 0) +
45          (x ? 1 : 0) +
46          (x ? 1 : 0) +
47          (x ? 1 : 0) +
48          (x ? 1 : 0) +
49          (x ? 1 : 0);
50    }
51  }
52
53  static class MyClass {
54    static class MyInnerClass {
55    }
56  }
57
58  public void testSearchForInnerClasses() throws Exception {
59    String name = "com.google.test.metric.JavaClassRepositoryTest.MyClass.MyInnerClass";
60    assertEquals(name, repository.getClass(name).getName());
61  }
62
63  public void testSearchForInnerClassesInPremordialClassloader() throws Exception {
64    String name = "java.util.Map.Entry";
65    assertEquals(name, repository.getClass(name).getName());
66  }
67
68}