/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

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