/** * Assert that the upstream is a fuseable source. * <p>Package-private: avoid leaking the now internal fusion properties into the public API. * Use ObserverFusion to work with such tests. * @return this */ final TestObserver<T> assertFuseable() { if (qd == null) { throw new AssertionError("Upstream is not fuseable."); } return this; }
/** * Returns true if {@code e} is due to a firmware bug fixed after Android 4.2.2. * https://code.google.com/p/android/issues/detail?id=54072 */ public static boolean isAndroidGetsocknameError(AssertionError e) { return e.getCause() != null && e.getMessage() != null && e.getMessage().contains("getsockname failed"); }
/** Alternative to AssertionError(String, Throwable), which doesn't exist in Java 1.6 */ private static AssertionError newAssertionError(String message, Throwable cause) { AssertionError e = new AssertionError(message); e.initCause(cause); return e; } }
@Test public void assertValueSetMissing() { Set<Integer> set = new HashSet<Integer>(Arrays.asList(0, 1, 2, 4, 5, 6, 7)); try { Observable.range(1, 5) .test() .assertValueSet(set); throw new RuntimeException("Should have failed"); } catch (AssertionError ex) { assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3)); } } }
@Test public void assertNoTimeout2() { try { Flowable.never() .test() .awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50) .assertNoTimeout(); throw new RuntimeException("Should have thrown!"); } catch (AssertionError ex) { assertTrue(ex.toString(), ex.getMessage().contains("Timeout?!")); } }
@Test public void assertValueSetMissing() { Set<Integer> set = new HashSet<Integer>(Arrays.asList(0, 1, 2, 4, 5, 6, 7)); try { Flowable.range(1, 5) .test() .assertValueSet(set); throw new RuntimeException("Should have failed"); } catch (AssertionError ex) { assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3)); } } }
@Test public void assertTimeout2() { try { Flowable.empty() .test() .awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50) .assertTimeout(); throw new RuntimeException("Should have thrown!"); } catch (AssertionError ex) { assertTrue(ex.toString(), ex.getMessage().contains("No timeout?!")); } }
/** * Assert that the upstream is not a fuseable source. * <p>Package-private: avoid leaking the now internal fusion properties into the public API. * Use ObserverFusion to work with such tests. * @return this */ final TestObserver<T> assertNotFuseable() { if (qd != null) { throw new AssertionError("Upstream is fuseable."); } return this; }
/** Alternative to AssertionError(String, Throwable), which doesn't exist in GWT 2.6.1. */ private static AssertionError newAssertionError(String message, Throwable cause) { AssertionError e = new AssertionError(message); e.initCause(cause); return e; }
@Test public void headerContainsWithMissingHeader() throws Exception { AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.header("foo", containsString("baz")).match(this.request)); assertThat(error.getMessage(), containsString("but was null")); }
/** * Assert that the upstream is a fuseable source. * <p>Package-private: avoid leaking the now internal fusion properties into the public API. * Use SubscriberFusion to work with such tests. * @return this */ final TestSubscriber<T> assertFuseable() { if (qs == null) { throw new AssertionError("Upstream is not fuseable."); } return this; }
public static void assertError(List<Throwable> list, int index, Class<? extends Throwable> clazz) { Throwable ex = list.get(index); if (!clazz.isInstance(ex)) { AssertionError err = new AssertionError(clazz + " expected but got " + list.get(index)); err.initCause(list.get(index)); throw err; } }
@Test public void queryParamContainsWithMissingValue() throws Exception { this.request.setURI(new URI("http://foo.com/a?foo=bar&foo=baz")); AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.queryParam("foo", containsString("bx")).match(this.request)); assertThat(error.getMessage(), containsString("was \"bar\"")); }
/** * Assert that the upstream is not a fuseable source. * <p>Package-private: avoid leaking the now internal fusion properties into the public API. * Use SubscriberFusion to work with such tests. * @return this */ final TestSubscriber<T> assertNotFuseable() { if (qs != null) { throw new AssertionError("Upstream is fuseable."); } return this; }
public static void assertError(List<Throwable> list, int index, Class<? extends Throwable> clazz, String message) { Throwable ex = list.get(index); if (!clazz.isInstance(ex)) { AssertionError err = new AssertionError("Type " + clazz + " expected but got " + ex); err.initCause(ex); throw err; } if (!ObjectHelper.equals(message, ex.getMessage())) { AssertionError err = new AssertionError("Message " + message + " expected but got " + ex.getMessage()); err.initCause(ex); throw err; } }
@Test public void headerMissing() throws Exception { AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.header("foo", "bar").match(this.request)); assertThat(error.getMessage(), containsString("was null")); }
/** Throws {@code throwable} as either an IOException, RuntimeException, or Error. */ private static IOException propagate(Throwable throwable) throws IOException { if (throwable instanceof IOException) throw (IOException) throwable; if (throwable instanceof Error) throw (Error) throwable; if (throwable instanceof RuntimeException) throw (RuntimeException) throwable; throw new AssertionError(); }
public static void assertUndeliverable(List<Throwable> list, int index, Class<? extends Throwable> clazz) { Throwable ex = list.get(index); if (!(ex instanceof UndeliverableException)) { AssertionError err = new AssertionError("Outer exception UndeliverableException expected but got " + list.get(index)); err.initCause(list.get(index)); throw err; } ex = ex.getCause(); if (!clazz.isInstance(ex)) { AssertionError err = new AssertionError("Inner exception " + clazz + " expected but got " + list.get(index)); err.initCause(list.get(index)); throw err; } }
@Test public void headersWithMissingHeader() throws Exception { AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.header("foo", "bar").match(this.request)); assertThat(error.getMessage(), containsString("but was null")); }
@Override Cut<Comparable<?>> withUpperBoundType( BoundType boundType, DiscreteDomain<Comparable<?>> domain) { throw new AssertionError("this statement should be unreachable"); }