public void testToString_addWithNullName() { MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(new TestClass()); try { helper.add(null, "Hello"); fail("No exception was thrown."); } catch (NullPointerException expected) { } }
public void testGetRootCause_DoubleWrapped() { SomeCheckedException cause = new SomeCheckedException(); SomeChainingException exception = new SomeChainingException(new SomeChainingException(cause)); assertSame(cause, Throwables.getRootCause(exception)); }
public void testCheckArgument_simpleMessage_failure() { try { Preconditions.checkArgument(false, new Message()); fail("no exception thrown"); } catch (IllegalArgumentException expected) { verifySimpleMessage(expected); } }
public void testCheckState_simpleMessage_failure() { try { Preconditions.checkState(false, new Message()); fail("no exception thrown"); } catch (IllegalStateException expected) { verifySimpleMessage(expected); } }
public void testIdentity_same() { Function<String, String> identity = Functions.identity(); assertNull(identity.apply(null)); assertSame("foo", identity.apply("foo")); }
public void testIsEqualTo_apply() { Predicate<Integer> isOne = Predicates.equalTo(1); assertTrue(isOne.apply(1)); assertFalse(isOne.apply(2)); assertFalse(isOne.apply(null)); }
public void testIsNull_apply() { Predicate<Integer> isNull = Predicates.isNull(); assertTrue(isNull.apply(null)); assertFalse(isNull.apply(1)); }
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatThrowsUnchecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t, SomeCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void noneDeclared() { try { methodThatThrowsUndeclaredChecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new SomeChainingException(t); } } };
@Override public void noneDeclared() { try { methodThatDoesntThrowAnything(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new SomeChainingException(t); } } };
public void testThrowIfUnchecked_Error() { try { throwIfUnchecked(new SomeError()); fail(); } catch (SomeError expected) { } }
public void testThrowIfUnchecked_Unchecked() { try { throwIfUnchecked(new SomeUncheckedException()); fail(); } catch (SomeUncheckedException expected) { } }
public void testMapSplitter_duplicateKeys() { try { COMMA_SPLITTER.withKeyValueSeparator(":").split("a:1,b:2,a:3"); fail(); } catch (IllegalArgumentException expected) { } }
public void testConverterToBackward() { assertEquals("FOO_BAR", UPPER_UNDERSCORE.converterTo(UPPER_CAMEL).reverse().convert("FooBar")); assertEquals("FOO_BAR", UPPER_UNDERSCORE.converterTo(LOWER_CAMEL).reverse().convert("fooBar")); assertEquals("FooBar", UPPER_CAMEL.converterTo(UPPER_UNDERSCORE).reverse().convert("FOO_BAR")); assertEquals("fooBar", LOWER_CAMEL.converterTo(UPPER_UNDERSCORE).reverse().convert("FOO_BAR")); }
@Override public void noneDeclared() { try { methodThatThrowsUnchecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t); throw new SomeChainingException(t); } } };
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatThrowsUndeclaredChecked(); } catch (Throwable t) { Throwables.propagateIfPossible(t, SomeCheckedException.class); throw new SomeChainingException(t); } } };
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatDoesntThrowAnything(); } catch (Throwable t) { // yes, this block is never reached, but for purposes of illustration // we're keeping it the same in each test Throwables.propagateIfPossible(t, SomeCheckedException.class); throw new SomeChainingException(t); } } };
public void testGetRootCause_SingleWrapped() { SomeCheckedException cause = new SomeCheckedException(); SomeChainingException exception = new SomeChainingException(cause); assertSame(cause, Throwables.getRootCause(exception)); }
@Override public void twoDeclared() throws SomeCheckedException, SomeOtherCheckedException { try { methodThatThrowsUnchecked(); } catch (Throwable t) { Throwables.propagateIfPossible( t, SomeCheckedException.class, SomeOtherCheckedException.class); throw new SomeChainingException(t); } } };