List of usage examples for junit.framework AssertionFailedError AssertionFailedError
public AssertionFailedError(String message)
From source file:com.mtgi.analytics.aop.config.v11.HttpRequestsConfigurationTest.java
/** test the graceful handling of various runtime errors by the filter */ @Test//from w w w .j ava 2 s. c o m public void testExceptionHandling() throws Exception { TestServlet.servletException = new ServletException("servlet boom"); try { webClient.getPage(baseUrl + "/app/foo.ext?param1=SE"); fail("non-OK status should have been sent back by test servlet"); } catch (FailingHttpStatusCodeException expected) { assertNotNull("Servlet was hit", servlet); assertEquals("Server status code sent back", 500, expected.getStatusCode()); } TestServlet.ioException = new IOException("IO boom"); try { webClient.getPage(baseUrl + "/app/foo.ext?param1=IOE"); fail("non-OK status should have been sent back by test servlet"); } catch (FailingHttpStatusCodeException expected) { assertNotNull("Servlet was hit", servlet); assertEquals("Server status code sent back", 500, expected.getStatusCode()); } TestServlet.runtimeException = new NullPointerException("Should have written a unit test"); try { webClient.getPage(baseUrl + "/app/foo.ext?param1=RE"); fail("non-OK status should have been sent back by test servlet"); } catch (FailingHttpStatusCodeException expected) { assertNotNull("Servlet was hit", servlet); assertEquals("Server status code sent back", 500, expected.getStatusCode()); } TestServlet.error = new AssertionFailedError("Might as well try to trap these"); try { webClient.getPage(baseUrl + "/app/foo.ext?param1=E"); fail("non-OK status should have been sent back by test servlet"); } catch (FailingHttpStatusCodeException expected) { assertNotNull("Servlet was hit", servlet); assertEquals("Server status code sent back", 500, expected.getStatusCode()); } }
From source file:org.opennms.core.test.MockLogAppender.java
/** * <p>assertLogAtLevel</p>// w w w . j a v a 2s .co m * Asserts that a message was logged at the requested level. * * Useful for testing code that *should* have logged an error message * (or a notice or some other special case) * * @throws junit.framework.AssertionFailedError if any. */ public static void assertLogAtLevel(final Level level) throws AssertionFailedError { if (!isLoggingSetup()) { throw new AssertionFailedError("MockLogAppender has not been initialized"); } /* try { Thread.sleep(500); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); } */ final LoggingEvent[] events = getEventsAtLevel(level); if (events.length == 0) { throw new AssertionFailedError("No messages were received at level " + level); } }
From source file:fi.hsl.parkandride.itest.RequestLogITest.java
private void concurrentlyGenerateLogs(int numberOfRequests, int numberOfUpdates) { withDate(DateTime.now().withTime(12, 2, 0, 0), () -> { final Stream<CompletableFuture<Integer>> statusCodes = range(0, numberOfRequests).parallel() .mapToObj(i -> {// www.j a v a 2s . c o m final Response response = given().header(SOURCE_HEADER, WEB_UI_SOURCE).when() .get(UrlSchema.CAPACITY_TYPES).thenReturn(); return CompletableFuture.completedFuture(response.statusCode()); }); final Stream<CompletableFuture<Integer>> updates = range(0, numberOfUpdates).parallel().mapToObj(i -> { batchingRequestLogService.updateRequestLogs(); return CompletableFuture.completedFuture(0); }); try { CompletableFuture.allOf(Stream.concat(statusCodes, updates).toArray(i -> new CompletableFuture[i])) .get(); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); throw new AssertionFailedError(e.getMessage()); } }); }
From source file:CalendarUtilsTest.java
/** * This checks that this is a 7 divisble iterator of Calendar objects * that are dates (no time), and exactly 1 day spaced after each other * (in addition to the proper start and stop dates) *//*w w w. j a v a 2 s . com*/ private static void assertWeekIterator(Iterator it, Calendar start, Calendar end) { Calendar cal = (Calendar) it.next(); assertEquals("", start, cal, 0); Calendar last = null; int count = 1; while (it.hasNext()) { //Check this is just a date (no time component) assertEquals("", cal, CalendarUtils.trunc(cal, Calendar.DATE), 0); last = cal; cal = (Calendar) it.next(); count++; //Check that this is one day more than the last date last.add(Calendar.DATE, 1); assertEquals("", last, cal, 0); } if (count % 7 != 0) { throw new AssertionFailedError("There were " + count + " days in this iterator"); } assertEquals("", end, cal, 0); }
From source file:org.opennms.core.test.MockLogAppender.java
public static void assertNoLogging() throws AssertionFailedError { if (s_events.size() > 0) { throw new AssertionFailedError("Unhandled logging occurred."); }/*from w ww.ja va2 s.co m*/ }
From source file:CalendarUtilsTest.java
/** * Used to check that Calendar objects are close enough * delta is in milliseconds//from w ww . j av a 2 s . c o m */ public static void assertEquals(String message, Calendar cal1, Calendar cal2, long delta) { if (Math.abs(cal1.getTime().getTime() - cal2.getTime().getTime()) > delta) { throw new AssertionFailedError(message + " expected " + cal1.getTime() + " but got " + cal2.getTime()); } }
From source file:org.opennms.core.test.MockLogAppender.java
public static void assertLogMatched(final Level level, final String message) { for (final LoggingEvent event : s_events) { if (event.getLevel().eq(level) && event.getMessage().contains(message)) { return; }/*from w w w. j a v a 2s .c o m*/ } throw new AssertionFailedError( "No log message matched for log level " + level + ", message '" + message + "'"); }
From source file:ir.keloud.android.lib.test_project.test.KeloudClientTest.java
public void testGetSetBaseUri() { KeloudClient client = new KeloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); assertEquals("Returned base URI different that URI passed to constructor", mServerUri, client.getBaseUri()); Uri otherUri = Uri.parse("https://whatever.com/basePath/here"); client.setBaseUri(otherUri);//from ww w .j a va2 s. c om assertEquals("Returned base URI different that URI passed to constructor", otherUri, client.getBaseUri()); try { client.setBaseUri(null); throw new AssertionFailedError("Accepted NULL parameter"); } catch (Exception e) { assertTrue("Unexpected exception passing NULL base URI", (e instanceof IllegalArgumentException)); } }
From source file:com.owncloud.android.lib.test_project.test.OwnCloudClientTest.java
public void testGetSetBaseUri() { OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager()); assertEquals("Returned base URI different that URI passed to constructor", mServerUri, client.getBaseUri()); Uri otherUri = Uri.parse("https://whatever.com/basePath/here"); client.setBaseUri(otherUri);/* w w w . ja v a 2 s .c o m*/ assertEquals("Returned base URI different that URI passed to constructor", otherUri, client.getBaseUri()); try { client.setBaseUri(null); throw new AssertionFailedError("Accepted NULL parameter"); } catch (Exception e) { assertTrue("Unexpected exception passing NULL base URI", (e instanceof IllegalArgumentException)); } }