Refine search
public void testToString() { Future<?> first = serializer.submitAsync(firstCallable, directExecutor()); TestCallable secondCallable = new TestCallable(SettableFuture.<Void>create()); Future<?> second = serializer.submitAsync(secondCallable, directExecutor()); assertThat(secondCallable.called).isFalse(); assertThat(second.toString()).contains(secondCallable.toString()); firstFuture.set(null); assertThat(second.toString()).contains(secondCallable.future.toString()); }
public void testToOptionalMany() { try { Stream.of(1, 2, 3, 4, 5, 6).collect(MoreCollectors.toOptional()); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("1, 2, 3, 4, 5, ..."); } }
public void testOnlyElementMany() { try { Stream.of(1, 2, 3, 4, 5, 6).collect(MoreCollectors.onlyElement()); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("1, 2, 3, 4, 5, ..."); } } }
public void testOnlyElementMultiple() { try { Stream.of(1, 2).collect(MoreCollectors.onlyElement()); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("1, 2"); } }
/** Can't create the map if more than one value maps to the same key. */ public void testUniqueIndexDuplicates() { try { Map<Integer, String> unused = Maps.uniqueIndex(ImmutableSet.of("one", "uno"), Functions.constant(1)); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("Multimaps.index"); } }
private static void assertCastFails(long value) { try { UnsignedInts.checkedCast(value); fail("Cast to int should have failed: " + value); } catch (IllegalArgumentException ex) { assertThat(ex.getMessage()).contains(String.valueOf(value)); } }
public void testSetFutureSelf_toString() { SettableFuture<String> orig = SettableFuture.create(); orig.setFuture(orig); assertThat(orig.toString()).contains("[status=PENDING, info=[setFuture=[this future]]]"); }
public void testOfWithDuplicateKey() { try { ImmutableBiMap.of("one", 1, "one", 1); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("one"); } }
public void testToString() throws Exception { Service a = new NoOpService(); Service b = new FailStartService(); ServiceManager manager = new ServiceManager(asList(a, b)); String toString = manager.toString(); assertThat(toString).contains("NoOpService"); assertThat(toString).contains("FailStartService"); }
public void testCheckInRange_failure() { try { MathPreconditions.checkInRangeForRoundingInputs(false, 1.0, RoundingMode.UP); fail(); } catch (ArithmeticException expected) { assertThat(expected).hasMessageThat().contains("1.0"); assertThat(expected).hasMessageThat().contains("UP"); } }
@Test public void addEdge_selfLoop() { try { putEdge(N1, N1); fail(ERROR_ADDED_SELF_LOOP); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains(ERROR_SELF_LOOP); } }
public void testNonStaticInnerClass() { try { new NullPointerTester().testAllPublicConstructors(Inner.class); fail(); } catch (IllegalArgumentException expected) { assertThat(expected.getMessage()).contains("inner class"); } }
@Test public void addEdge_selfLoop() { try { addEdge(N1, N1, E11); fail(ERROR_ADDED_SELF_LOOP); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains(ERROR_SELF_LOOP); } }
private void assertBadUseOfReferentialEquality(Class<?> cls) throws Exception { try { tester.testEquals(cls); } catch (AssertionFailedError expected) { assertThat(expected.getMessage()).contains(cls.getSimpleName() + "("); return; } fail("should have failed for " + cls); }
@Test public void addEdge_selfLoop() { try { putEdge(N1, N1); fail(ERROR_ADDED_SELF_LOOP); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains(ERROR_SELF_LOOP); } }
@Test public void addEdge_selfLoop() { try { addEdge(N1, N1, E11); fail(ERROR_ADDED_SELF_LOOP); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains(ERROR_SELF_LOOP); } }
public void testMessageNoException() throws Exception { Method method = OneArg.class.getMethod("staticOneArgShouldThrowNpeButDoesnt", String.class); boolean foundProblem = false; try { new NullPointerTester().testMethodParameter(new OneArg(), method, 0); } catch (AssertionFailedError expected) { assertThat(expected.getMessage()).contains("index 0"); assertThat(expected.getMessage()).contains("[null]"); foundProblem = true; } assertTrue("Should report error when no exception is thrown", foundProblem); }
public void testMessageOtherException() throws Exception { Method method = OneArg.class.getMethod("staticOneArgThrowsOtherThanNpe", String.class); boolean foundProblem = false; try { new NullPointerTester().testMethodParameter(new OneArg(), method, 0); } catch (AssertionFailedError expected) { assertThat(expected.getMessage()).contains("index 0"); assertThat(expected.getMessage()).contains("[null]"); foundProblem = true; } assertTrue("Should report error when different exception is thrown", foundProblem); }
public void testImmediateFuture() throws Exception { ListenableFuture<String> future = immediateFuture(DATA1); assertSame(DATA1, getDone(future)); assertSame(DATA1, getDoneFromTimeoutOverload(future)); assertThat(future.toString()).contains("[status=SUCCESS, result=[" + DATA1 + "]]"); }
public void testInstantiate_factoryMethodReturnsNullButNotAnnotated() throws Exception { try { tester.instantiate(FactoryMethodReturnsNullButNotAnnotated.class); } catch (AssertionFailedError expected) { assertThat(expected.getMessage()).contains("@Nullable"); return; } fail("should have failed"); }