コード例 #1
0
 @Test
 public void shouldGetLocationForClassInJarWithVersion() {
   assertEquals(
       "Location not retrieved for java.lang.reflect.Method",
       enricher.getLocation(java.lang.reflect.Method.class),
       RT_JAR);
 }
コード例 #2
0
 @Test
 public void shouldGetVersionForStackTraceElementInJarWithVersion() {
   StackTraceElement javaLangElement = getJavaLangStackTraceElement(exception);
   assertTrue(
       "Version not retrieved for " + javaLangElement.getClassName(),
       enricher.getVersion(javaLangElement).contains(javaVersion));
 }
コード例 #3
0
 @Test
 public void shouldWriteEnrichedStackTraceToWriter() throws Exception {
   StringWriter writer = new StringWriter();
   enricher.printStackTrace(exception, writer);
   assertTrue(
       "JUnit jar " + JUNIT_JAR_PATTERN + " not found in stack trace written to writer",
       writer.toString().contains(JUNIT_JAR_PATTERN));
 }
コード例 #4
0
 @Test
 public void shouldGetLocationForStackTraceElementInJarWithVersion() {
   StackTraceElement javaLangElement = getJavaLangStackTraceElement(exception);
   assertEquals(
       "Version not retrieved for " + javaLangElement.getClassName(),
       enricher.getLocation(javaLangElement),
       RT_JAR);
 }
コード例 #5
0
 @Test
 public void shouldWriteEnrichedStackTraceToOutputStream() throws Exception {
   ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
   enricher.printStackTrace(exception, outputStream);
   String output = new String(outputStream.toByteArray());
   assertTrue(
       "JUnit jar " + JUNIT_JAR_PATTERN + " not found in stack trace written to output stream",
       output.contains(JUNIT_JAR_PATTERN));
 }
コード例 #6
0
 @Test
 public void shouldWriteToSystemErrByDefault() {
   PrintStream originalErrStream = System.err;
   try {
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     System.setErr(new PrintStream(out));
     enricher.printStackTrace(exception);
     String output = new String(out.toByteArray());
     assertTrue(
         "JUnit jar "
             + JUNIT_JAR_PATTERN
             + " not found in stack trace written to default System.err stream",
         output.contains(JUNIT_JAR_PATTERN));
   } finally {
     System.setErr(originalErrStream);
   }
 }
コード例 #7
0
 @Test
 public void shouldParseDirectories() {
   String classPath = System.getProperty("java.class.path");
   classPath = classPath.replace('\\', '/');
   String testLocation = enricher.getLocation(this.getClass());
   if (!testLocation.contains(".jar")) {
     testLocation = testLocation.replace('\\', '/');
     if (testLocation.startsWith("file:/")) {
       testLocation = testLocation.substring("file:/".length());
     }
     if (testLocation.endsWith("/")) {
       testLocation = testLocation.substring(0, testLocation.length() - 1);
     }
     assertTrue(
         "Location of unit test (" + testLocation + ") not found on the classpath.",
         classPath.contains(testLocation));
   } else {
     // TODO Find a way to test this if the unit test is executed from a jar.
     System.err.println(
         "Unit test executed from jar file, no stable method available for testing the parsing of "
             + "directory locations.");
   }
 }
コード例 #8
0
 @Test
 public void shouldParseRtJar() {
   assertTrue(
       "Java RT jar not properly determined.",
       enricher.getStackTraceAsString(exception).contains(RT_JAR));
 }
コード例 #9
0
 @Test
 public void shouldReturnEnrichedStackTraceAsString() {
   assertTrue(
       "JUnit jar " + JUNIT_JAR_PATTERN + " not found in stack trace as String",
       enricher.getStackTraceAsString(exception).contains(JUNIT_JAR_PATTERN));
 }
コード例 #10
0
 @Test
 public void shouldGetVersionForClassInJarWithVersion() {
   assertTrue(
       "Version not retrieved for java.lang.reflect.Method",
       enricher.getVersion(java.lang.reflect.Method.class).contains(javaVersion));
 }
コード例 #11
0
 @Test
 public void shouldAddVersionWhenAvailable() {
   assertTrue(
       "Version not added for rt.jar",
       enricher.getStackTraceAsString(exception).contains(RT_JAR + ":" + javaVersion));
 }