private static void assertParseException(int offset, String message, final String json) { ParseException exception = assertException( ParseException.class, new Runnable() { public void run() { parse(json); } }); assertEquals(offset, exception.getOffset()); assertThat(exception.getMessage(), StringStartsWith.startsWith(message + " at")); }
@Test public void testConfiguredRuntimeException() throws Throwable { try { conf.runAndThrow("foo", new RuntimeException("re message")); fail(); } catch (RuntimeException e) { assertThat( LogbackTestAppender.getMessage(), StringStartsWith.startsWith( "WARN call runAndThrow(objectParam=foo, throwable=java.lang.RuntimeException: re message) caused java.lang.RuntimeException: re message" + "\njava.lang.RuntimeException: re message" + "\n\tat com.github.sfleiter.cdi_interceptors.LoggingInterceptorTest.testConfiguredRuntimeException(LoggingInterceptorTest.java")); } }
@Test public void testDefaultCheckedException() throws Throwable { try { def.runAndThrow("foo", new Exception("e message")); fail(); } catch (Exception e) { assertThat( LogbackTestAppender.getMessage(), StringStartsWith.startsWith( "INFO call runAndThrow(objectParam=foo, throwable=java.lang.Exception: e message) caused java.lang.Exception: e message" + "\njava.lang.Exception: e message" + "\n\tat com.github.sfleiter.cdi_interceptors.LoggingInterceptorTest.testDefaultCheckedException(LoggingInterceptorTest.java")); } }
@Test public void parse_rejectsEmptyReader() { ParseException exception = assertException( ParseException.class, new Runnable() { public void run() { try { new JsonParser(new StringReader("")).parse(); } catch (IOException exception) { throw new RuntimeException(exception); } } }); assertEquals(0, exception.getOffset()); assertThat(exception.getMessage(), StringStartsWith.startsWith("Unexpected end of input at")); }
public List<TreeItem> getRESTValidationErrors( String wsProjectName, String description, int expectedCount) { Matcher<String> descriptionMatcher = description != null ? StringContains.containsString(description) : null; Matcher<String> pathMatcher = wsProjectName != null ? StringStartsWith.startsWith("/" + wsProjectName) : null; /* wait for jax-rs validation */ if (expectedCount == 0 && !new ProblemsExists() .test()) { // prevent from false positive result when we do not expect errors and there // is no error new WaitWhile( new ProblemsCount( ProblemsCount.ProblemType.ERROR, expectedCount, descriptionMatcher, null, pathMatcher, null, null), WAIT_FOR_PROBLEMS_FALSE_POSItIVE_TIMEOUT, false); } else { // prevent from false negative result new WaitUntil( new ProblemsCount( ProblemsCount.ProblemType.ERROR, expectedCount, descriptionMatcher, null, pathMatcher, null, null), WAIT_FOR_PROBLEMS_FALSE_NEGATIVE_TIMEOUT, false); } /* return jax-rs validation errors */ return new ProblemsView() .getErrors(descriptionMatcher, null, pathMatcher, null, Is.is(JAX_RS_PROBLEM)); }
public List<TreeItem> getRESTValidationWarnings( String wsProjectName, String description, int expectedCount) { Matcher<String> descriptionMatcher = description != null ? StringContains.containsString(description) : null; Matcher<String> pathMatcher = wsProjectName != null ? StringStartsWith.startsWith("/" + wsProjectName) : null; /* wait for warnings */ if (expectedCount == 0) { // prevent from false-positive new WaitWhile( new ProblemsCount( ProblemsCount.ProblemType.WARNING, expectedCount, descriptionMatcher, null, pathMatcher, null, Is.is(JAX_RS_PROBLEM)), WAIT_FOR_PROBLEMS_FALSE_POSItIVE_TIMEOUT, false); } else { // prevent from false-negative new WaitUntil( new ProblemsCount( ProblemsCount.ProblemType.WARNING, expectedCount, descriptionMatcher, null, pathMatcher, null, Is.is(JAX_RS_PROBLEM)), WAIT_FOR_PROBLEMS_FALSE_NEGATIVE_TIMEOUT, false); } /* return jax-rs validation warnings */ return new ProblemsView() .getWarnings(descriptionMatcher, null, pathMatcher, null, Is.is(JAX_RS_PROBLEM)); }