@Test public void testDeclaringClassToNull() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { java.lang.Throwable some = new java.lang.Throwable("contains null"); java.lang.StackTraceElement ste = new java.lang.StackTraceElement("class", "method", null, 1); Field field = java.lang.StackTraceElement.class.getDeclaredField("declaringClass"); field.setAccessible(true); field.set(ste, null); some.setStackTrace(new java.lang.StackTraceElement[] {ste}); Throwable sut = Reports.newThrowable(some); Assert.assertEquals("MISSING", sut.getStackTrace().get(0).getClassName()); }
@Test public void testCreateAnonymizedSendCopyAnonymizes() { ModelFactory mf = ModelFactory.eINSTANCE; ErrorReport report = mf.createErrorReport(); report.setStatus(mf.createStatus()); java.lang.Throwable throwable = new RuntimeException("test exception"); throwable.fillInStackTrace(); Throwable t = Reports.newThrowable(throwable); report.getStatus().setException(t); settings.setAnonymizeMessages(true); settings.setAnonymizeStrackTraceElements(true); configuration.setAcceptedPackages(new ArrayList<String>()); ErrorReport copy = Reports.createAnonymizedSendCopy(report, settings, configuration); assertThat(copy.getStatus().getMessage(), is(Constants.HIDDEN)); StackTraceElement stackTraceElement = copy.getStatus().getException().getStackTrace().get(0); assertThat(stackTraceElement.getClassName(), is(Constants.HIDDEN)); assertThat(stackTraceElement.getMethodName(), is(Constants.HIDDEN)); assertThat(stackTraceElement.getFileName(), is(Constants.HIDDEN)); assertThat(stackTraceElement.getLineNumber(), is(-1)); }