code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
@Test public void hasMessageThat_messageHasNullMessage_failure() { expectFailure( whenTesting -> whenTesting.that(new NullPointerException("message")).hasMessageThat().isNull()); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasMessageThat_messageHasNullMessage_failure
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasMessageThat_nullMessageHasMessage_failure() { NullPointerException npe = new NullPointerException(null); expectFailure(whenTesting -> whenTesting.that(npe).hasMessageThat().isEqualTo("message")); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasMessageThat_nullMessageHasMessage_failure
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasMessageThat_tooDeep_failure() { Exception actual = new Exception("foobar"); AssertionError e = expectFailure( whenTesting -> whenTesting.that(actual).hasCauseThat().hasMessageThat().isNull()); assertFailureKeys( e, "Attempt to assert about the message of a null Throwable", "null Throwable was"); assertFailureValue(e, "null Throwable was", "throwable.getCause()"); assertErrorHasActualAsCause(actual, e); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasMessageThat_tooDeep_failure
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasMessageThat_onNull() { AssertionError e = expectFailure(whenTesting -> whenTesting.that((Throwable) null).hasMessageThat()); assertFailureKeys(e, "Attempt to assert about the message of a null Throwable"); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasMessageThat_onNull
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasCauseThat_message() { assertThat(new Exception("foobar", new IOException("barfoo"))) .hasCauseThat() .hasMessageThat() .isEqualTo("barfoo"); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasCauseThat_message
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasCauseThat_instanceOf() { assertThat(new Exception("foobar", new IOException("barfoo"))) .hasCauseThat() .isInstanceOf(IOException.class); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasCauseThat_instanceOf
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasCauseThat_null() { assertThat(new Exception("foobar")).hasCauseThat().isNull(); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasCauseThat_null
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasCauseThat_message_failure() { Exception actual = new Exception("foobar", new IOException("barfoo")); AssertionError e = expectFailure( whenTesting -> whenTesting.that(actual).hasCauseThat().hasMessageThat().isEqualTo("message")); assertFailureValue(e, "value of", "throwable.getCause().getMessage()"); assertErrorHasActualAsCause(actual, e); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasCauseThat_message_failure
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasCauseThat_instanceOf_failure() { Exception actual = new Exception("foobar", new IOException("barfoo")); AssertionError e = expectFailure( whenTesting -> whenTesting.that(actual).hasCauseThat().isInstanceOf(RuntimeException.class)); assertFailureValue(e, "value of", "throwable.getCause()"); assertErrorHasActualAsCause(actual, e); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasCauseThat_instanceOf_failure
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasCauseThat_tooDeep_failure() { Exception actual = new Exception("foobar"); AssertionError e = expectFailure( whenTesting -> whenTesting.that(actual).hasCauseThat().hasCauseThat().isNull()); assertFailureKeys( e, "Attempt to assert about the cause of a null Throwable", "null Throwable was"); assertFailureValue(e, "null Throwable was", "throwable.getCause()"); assertErrorHasActualAsCause(actual, e); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasCauseThat_tooDeep_failure
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasCauseThat_onNull() { AssertionError e = expectFailure(whenTesting -> whenTesting.that((Throwable) null).hasCauseThat()); assertFailureKeys(e, "Attempt to assert about the cause of a null Throwable"); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasCauseThat_onNull
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void hasCauseThat_deepNull_failure() { Exception actual = new Exception("foobar", new RuntimeException("barfoo", new IOException("buzz"))); AssertionError e = expectFailure( whenTesting -> whenTesting .that(actual) .hasCauseThat() .hasCauseThat() .hasMessageThat() .isEqualTo("message")); assertFailureValue(e, "value of", "throwable.getCause().getCause().getMessage()"); assertErrorHasActualAsCause(actual, e); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
hasCauseThat_deepNull_failure
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
@Test public void inheritedMethodChainsSubject() { NullPointerException expected = new NullPointerException("expected"); NullPointerException actual = new NullPointerException("actual"); AssertionError e = expectFailure(whenTesting -> whenTesting.that(actual).isEqualTo(expected)); assertErrorHasActualAsCause(actual, e); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
inheritedMethodChainsSubject
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
private static void assertErrorHasActualAsCause(Throwable actual, AssertionError failure) { assertWithMessage("AssertionError's cause").that(failure.getCause()).isEqualTo(actual); }
Tests for {@link Throwable} subjects. @author Kurt Alfred Kluever
assertErrorHasActualAsCause
java
google/truth
core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/ThrowableSubjectTest.java
Apache-2.0
private static TypeToken<?> methodToReturnTypeToken(Method input) { return TypeToken.of(Iterables.getOnlyElement(asList(input.getParameterTypes()))); }
Tests for the FEST-alike assertThat() entry point. @author Christian Gruber (cgruber@israfil.net)
methodToReturnTypeToken
java
google/truth
core/src/test/java/com/google/common/truth/TruthAssertThatTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/TruthAssertThatTest.java
Apache-2.0
@Test public void staticAssertThatMethodsMatchStandardSubjectBuilderInstanceMethods() { ImmutableSortedSet<TypeToken<?>> verbTypes = FluentIterable.from(asList(StandardSubjectBuilder.class.getMethods())) .filter(input -> input.getName().equals("that")) .transform(TruthAssertThatTest::methodToReturnTypeToken) .toSortedSet(Ordering.usingToString()); ImmutableSortedSet<TypeToken<?>> truthTypes = FluentIterable.from(asList(Truth.class.getMethods())) .filter( input -> input.getName().equals("assertThat") && Modifier.isStatic(input.getModifiers())) .transform(TruthAssertThatTest::methodToReturnTypeToken) .toSortedSet(Ordering.usingToString()); assert_().that(verbTypes).isNotEmpty(); assert_().that(truthTypes).isNotEmpty(); assert_().that(truthTypes).containsExactlyElementsIn(verbTypes); }
Tests for the FEST-alike assertThat() entry point. @author Christian Gruber (cgruber@israfil.net)
staticAssertThatMethodsMatchStandardSubjectBuilderInstanceMethods
java
google/truth
core/src/test/java/com/google/common/truth/TruthAssertThatTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/TruthAssertThatTest.java
Apache-2.0
public static EmployeeSubject assertThat(@Nullable Employee employee) { return assertAbout(employees()).that(employee); }
A <a href="https://github.com/google/truth">Truth</a> subject for {@link Employee}. @author Kurt Alfred Kluever (kak@google.com)
assertThat
java
google/truth
core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
Apache-2.0
public static Factory<EmployeeSubject, Employee> employees() { return EmployeeSubject::new; }
A <a href="https://github.com/google/truth">Truth</a> subject for {@link Employee}. @author Kurt Alfred Kluever (kak@google.com)
employees
java
google/truth
core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
Apache-2.0
public void isCeo() { if (!actual.isCeo()) { failWithActual(simpleFact("expected to be CEO")); } }
A <a href="https://github.com/google/truth">Truth</a> subject for {@link Employee}. @author Kurt Alfred Kluever (kak@google.com)
isCeo
java
google/truth
core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
Apache-2.0
public void isNotCeo() { if (actual.isCeo()) { failWithActual(simpleFact("expected not to be CEO")); } }
A <a href="https://github.com/google/truth">Truth</a> subject for {@link Employee}. @author Kurt Alfred Kluever (kak@google.com)
isNotCeo
java
google/truth
core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
Apache-2.0
public StringSubject name() { return check("name()").that(actual.name()); }
A <a href="https://github.com/google/truth">Truth</a> subject for {@link Employee}. @author Kurt Alfred Kluever (kak@google.com)
name
java
google/truth
core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
Apache-2.0
public StringSubject username() { return check("username()").that(actual.username()); }
A <a href="https://github.com/google/truth">Truth</a> subject for {@link Employee}. @author Kurt Alfred Kluever (kak@google.com)
username
java
google/truth
core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
Apache-2.0
public LongSubject id() { return check("id()").that(actual.id()); }
A <a href="https://github.com/google/truth">Truth</a> subject for {@link Employee}. @author Kurt Alfred Kluever (kak@google.com)
id
java
google/truth
core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
Apache-2.0
public ComparableSubject<Employee.Location> location() { return check("location()").that(actual.location()); }
A <a href="https://github.com/google/truth">Truth</a> subject for {@link Employee}. @author Kurt Alfred Kluever (kak@google.com)
location
java
google/truth
core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
Apache-2.0
public void put(Employee employee) { employees.put(employee.id(), employee); }
In-memory implementation of {@link HrDatabase}, suitable for testing.
put
java
google/truth
core/src/test/java/com/google/common/truth/extension/FakeHrDatabase.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/FakeHrDatabase.java
Apache-2.0
@Override public Employee get(long id) { return employees.get(id); }
In-memory implementation of {@link HrDatabase}, suitable for testing.
get
java
google/truth
core/src/test/java/com/google/common/truth/extension/FakeHrDatabase.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/FakeHrDatabase.java
Apache-2.0
@Override public void relocate(long id, Location location) { checkNotNull(location); Employee old = get(id); checkState(old != null, "No employee found with ID %s", id); employees.put(id, Employee.create(old.username(), old.id(), old.name(), location, old.isCeo())); }
In-memory implementation of {@link HrDatabase}, suitable for testing.
relocate
java
google/truth
core/src/test/java/com/google/common/truth/extension/FakeHrDatabase.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/FakeHrDatabase.java
Apache-2.0
@Override public ImmutableSet<Employee> getByLocation(Location location) { checkNotNull(location); ImmutableSet.Builder<Employee> result = ImmutableSet.builder(); for (Employee employee : employees.values()) { if (employee.location() == location) { result.add(employee); } } return result.build(); }
In-memory implementation of {@link HrDatabase}, suitable for testing.
getByLocation
java
google/truth
core/src/test/java/com/google/common/truth/extension/FakeHrDatabase.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/extension/FakeHrDatabase.java
Apache-2.0
@Override public String getModuleName() { return "com.google.common.truth.gwt.TruthTest"; }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
getModuleName
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testBuildClasses() { String unused = new Inventory().toString(); // force invocation. }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testBuildClasses
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testBoolean() { assertThat(true).isTrue(); assertThat(false).isFalse(); try { assertThat(true).isFalse(); } catch (AssertionError expected) { return; } }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testBoolean
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
@SuppressWarnings("TruthSelfEquals") public void testInteger() { assertThat(457923).isEqualTo(457923); try { assertThat(457923).isEqualTo(1); } catch (AssertionError expected) { return; } assert_().withMessage("Should have thrown an assertion error").fail(); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testInteger
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testString() { assertThat("blah").contains("ah"); assertThat("blah").startsWith("bl"); assertThat("blah").endsWith("ah"); try { assertThat("blah").contains("foo"); } catch (AssertionError expected) { return; } assert_().withMessage("Should have thrown an assertion error").fail(); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testString
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testString_match() { assertThat("blah").matches("b[la]+h"); assertThat("blah").matches("^b.+h$"); assertThat("blah").containsMatch("ah"); assertThat("blah").containsMatch("b[la]{2}h"); assertThat("blah").doesNotMatch("ah"); assertThat("blah").doesNotContainMatch("oh"); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testString_match
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testString_matchesFail() { try { assertThat("blah").matches("b[lu]+h"); } catch (AssertionError expected) { return; } assert_().withMessage("Should have thrown an assertion error").fail(); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testString_matchesFail
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testString_containsMatchFail() { try { assertThat("blah").containsMatch("o"); } catch (AssertionError expected) { return; } assert_().withMessage("Should have thrown an assertion error").fail(); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testString_containsMatchFail
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testString_doesNotMatchFail() { try { assertThat("blah").doesNotMatch("blah"); } catch (AssertionError expected) { return; } assert_().withMessage("Should have thrown an assertion error").fail(); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testString_doesNotMatchFail
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testString_doesNotContainMatchFail() { try { assertThat("blah").doesNotContainMatch("a"); } catch (AssertionError expected) { return; } assert_().withMessage("Should have thrown an assertion error").fail(); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testString_doesNotContainMatchFail
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testIterable() { assertThat((Iterable<Integer>) asList(1, 2, 3)).containsExactly(1, 2, 3).inOrder(); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testIterable
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testCollection() { assertThat((Collection<Integer>) asList(1, 2, 3)).containsExactly(1, 2, 3).inOrder(); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testCollection
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testList() { assertThat(asList(1, 2, 3)).containsExactly(1, 2, 3).inOrder(); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testList
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testObjectArray() { Set<?>[] setOfString = {new HashSet<String>(asList("foo", "bar", "bash"))}; assertThat(setOfString).asList().contains(new HashSet<String>(asList("foo", "bar", "bash"))); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testObjectArray
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
@SuppressWarnings("IsInstanceIterable") // test of an intentionally trivially true assertion public void testDefault() { assertThat(new Object()).isNotNull(); assertThat(new ArrayList<String>()).isInstanceOf(AbstractList.class); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testDefault
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
public void testLegacyAssert_() { assert_().that(new Object()).isNotNull(); assert_().that(new ArrayList<String>()).isInstanceOf(AbstractList.class); }
Test of Truth under GWT - should be enough tests here to force compilation of all Subject implementations. @author Christian Gruber (cgruber@israfil.net)
testLegacyAssert_
java
google/truth
core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
https://github.com/google/truth/blob/master/core/src/test/java/com/google/common/truth/gwt/TruthGwtTest.java
Apache-2.0
static Factory<LiteProtoSubject, MessageLite> liteProtos() { return LiteProtoSubjectFactory.INSTANCE; }
Returns a {@code Subject.Factory} for {@link MessageLite} subjects which you can use to assert things about Lite Protobuf properties.
liteProtos
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
static String getTrimmedToString(@Nullable MessageLite messageLite) { String subjectString = String.valueOf(messageLite); String trimmedSubjectString = subjectString.trim(); if (trimmedSubjectString.startsWith("# ")) { String objectToString = String.format( "# %s@%s", messageLite.getClass().getName(), Integer.toHexString(messageLite.hashCode())); if (trimmedSubjectString.startsWith(objectToString)) { subjectString = trimmedSubjectString.replaceFirst(Pattern.quote(objectToString), "").trim(); } } return subjectString.isEmpty() ? "[empty proto]" : subjectString; }
Returns a {@code Subject.Factory} for {@link MessageLite} subjects which you can use to assert things about Lite Protobuf properties.
getTrimmedToString
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
@Override protected String actualCustomStringRepresentation() { return actualCustomStringRepresentationForProtoPackageMembersToCall(); }
Returns a {@code Subject.Factory} for {@link MessageLite} subjects which you can use to assert things about Lite Protobuf properties.
actualCustomStringRepresentation
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
final String actualCustomStringRepresentationForProtoPackageMembersToCall() { return getTrimmedToString(actual); }
Returns a {@code Subject.Factory} for {@link MessageLite} subjects which you can use to assert things about Lite Protobuf properties.
actualCustomStringRepresentationForProtoPackageMembersToCall
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
@Override public void isEqualTo(@Nullable Object expected) { // TODO(user): Do better here when MessageLite descriptors are available. if (Objects.equals(actual, expected)) { return; } if (actual == null || expected == null) { super.isEqualTo(expected); } else if (actual.getClass() != expected.getClass()) { failWithoutActual( fact( "expected", expected instanceof MessageLite ? getTrimmedToString((MessageLite) expected) : expected), fact("an instance of", expected.getClass().getName()), fact("but was", getTrimmedToString(actual)), fact("an instance of", actual.getClass().getName())); } else { /* * TODO(cpovirk): If we someday let subjects override formatActualOrExpected(), change this * class to do so, and make this code path always delegate to super.isEqualTo(). */ String ourString = getTrimmedToString(actual); String theirString = getTrimmedToString((MessageLite) expected); if (!ourString.equals(theirString)) { new LiteProtoAsStringSubject(metadata, ourString).isEqualTo(theirString); // fails } else { // This will include the Object.toString() headers. super.isEqualTo(expected); } } }
Checks whether the MessageLite is equivalent to the argument, using the standard equals() implementation.
isEqualTo
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
@Deprecated public void isEqualTo(MessageLite.@Nullable Builder builder) { isEqualTo((Object) builder); }
@deprecated A Builder can never compare equal to a MessageLite instance. Use {@code build()}, or {@code buildPartial()} on the argument to get a MessageLite for comparison instead. Or, if you are passing {@code null}, use {@link #isNull()}.
isEqualTo
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
@Override public void isNotEqualTo(@Nullable Object expected) { if (Objects.equals(actual, expected)) { if (actual == null) { super.isNotEqualTo(expected); } else { failWithoutActual( simpleFact( lenientFormat( "Not true that protos are different. Both are (%s) <%s>.", actual.getClass().getName(), getTrimmedToString(actual)))); } } }
@deprecated A Builder can never compare equal to a MessageLite instance. Use {@code build()}, or {@code buildPartial()} on the argument to get a MessageLite for comparison instead. Or, if you are passing {@code null}, use {@link #isNull()}.
isNotEqualTo
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
@Deprecated public void isNotEqualTo(MessageLite.@Nullable Builder builder) { isNotEqualTo((Object) builder); }
@deprecated A Builder will never compare equal to a MessageLite instance. Use {@code build()}, or {@code buildPartial()} on the argument to get a MessageLite for comparison instead. Or, if you are passing {@code null}, use {@link #isNotNull()}.
isNotEqualTo
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
public void isEqualToDefaultInstance() { if (actual == null) { failWithoutActual( simpleFact( lenientFormat( "Not true that <%s> is a default proto instance. It is null.", actualCustomStringRepresentationForProtoPackageMembersToCall()))); } else if (!actual.equals(actual.getDefaultInstanceForType())) { failWithoutActual( simpleFact( lenientFormat( "Not true that <%s> is a default proto instance. It has set values.", actualCustomStringRepresentationForProtoPackageMembersToCall()))); } }
Checks whether the subject is a {@link MessageLite} with no fields set.
isEqualToDefaultInstance
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
public void isNotEqualToDefaultInstance() { if (actual != null && actual.equals(actual.getDefaultInstanceForType())) { failWithoutActual( simpleFact( lenientFormat( "Not true that (%s) <%s> is not a default proto instance. It has no set values.", actual.getClass().getName(), actualCustomStringRepresentationForProtoPackageMembersToCall()))); } }
Checks whether the subject is not equivalent to a {@link MessageLite} with no fields set.
isNotEqualToDefaultInstance
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
public void hasAllRequiredFields() { if (!actual.isInitialized()) { // MessageLite doesn't support reflection so this is the best we can do. failWithoutActual( simpleFact("expected to have all required fields set"), fact("but was", actualCustomStringRepresentationForProtoPackageMembersToCall()), simpleFact("(Lite runtime could not determine which fields were missing.)")); } }
Checks whether the subject has all required fields set. Cannot fail for a proto built with {@code build()}, which itself fails if required fields aren't set.
hasAllRequiredFields
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
public IntegerSubject serializedSize() { return check("getSerializedSize()").that(actual.getSerializedSize()); }
Returns an {@link IntegerSubject} on the serialized size of the MessageLite. <p>Assertions can then be changed on the serialized size, to support checks such as {@code assertThat(myProto).serializedSize().isAtLeast(16)}, etc.
serializedSize
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
@Override public LiteProtoSubject createSubject( FailureMetadata failureMetadata, @Nullable MessageLite messageLite) { return new LiteProtoSubject(failureMetadata, messageLite); }
Returns an {@link IntegerSubject} on the serialized size of the MessageLite. <p>Assertions can then be changed on the serialized size, to support checks such as {@code assertThat(myProto).serializedSize().isAtLeast(16)}, etc.
createSubject
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java
Apache-2.0
public static LiteProtoSubject assertThat(@Nullable MessageLite messageLite) { return assertAbout(liteProtos()).that(messageLite); }
A set of static methods to begin a Truth assertion chain for the lite version of protocol buffers. <p>This class implements a subset of what {@code ProtoTruth} provides, so if you are already using {@code ProtoTruth}, you should not import this class. {@code LiteProtoTruth} is only useful if you cannot depend on {@code ProtoTruth} for dependency management reasons. <p>Note: Usage of different failure strategies such as <em>assume</em> and <em>expect</em> should rely on {@linkplain com.google.common.truth.StandardSubjectBuilder#about(Subject.Factory) about(liteProtos())} to begin a chain with those alternative behaviors.
assertThat
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java
Apache-2.0
public static Subject.Factory<LiteProtoSubject, MessageLite> liteProtos() { return LiteProtoSubject.liteProtos(); }
A set of static methods to begin a Truth assertion chain for the lite version of protocol buffers. <p>This class implements a subset of what {@code ProtoTruth} provides, so if you are already using {@code ProtoTruth}, you should not import this class. {@code LiteProtoTruth} is only useful if you cannot depend on {@code ProtoTruth} for dependency management reasons. <p>Note: Usage of different failure strategies such as <em>assume</em> and <em>expect</em> should rely on {@linkplain com.google.common.truth.StandardSubjectBuilder#about(Subject.Factory) about(liteProtos())} to begin a chain with those alternative behaviors.
liteProtos
java
google/truth
extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java
Apache-2.0
public static Builder newBuilder() { return new AutoValue_LiteProtoSubjectTest_Config.Builder(); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
newBuilder
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Parameters(name = "{0}") public static Collection<Object[]> data() { // Missing a required_int field. TestMessageLite2WithRequiredFields withoutRequiredFields = TestMessageLite2WithRequiredFields.newBuilder().setOptionalString("foo").buildPartial(); Config proto2Config = Config.newBuilder() .setNonEmptyMessage(TestMessageLite2.newBuilder().setOptionalInt(3).build()) .setEquivalentNonEmptyMessage(TestMessageLite2.newBuilder().setOptionalInt(3).build()) .setNonEmptyMessageOfOtherValue( TestMessageLite2.newBuilder() .setOptionalInt(3) .setSubMessage( TestMessageLite2.SubMessage.newBuilder().setOptionalString("foo")) .build()) .setNonEmptyMessageOfOtherType( OtherTestMessageLite2.newBuilder().setOptionalInt(3).build()) .setDefaultInstance(TestMessageLite2.newBuilder().buildPartial()) .setDefaultInstanceOfOtherType(OtherTestMessageLite2.newBuilder().buildPartial()) .setMessageWithoutRequiredFields(withoutRequiredFields) .build(); Config proto3Config = Config.newBuilder() .setNonEmptyMessage(TestMessageLite3.newBuilder().setOptionalInt(3).build()) .setEquivalentNonEmptyMessage(TestMessageLite3.newBuilder().setOptionalInt(3).build()) .setNonEmptyMessageOfOtherValue( TestMessageLite3.newBuilder() .setOptionalInt(3) .setSubMessage( TestMessageLite3.SubMessage.newBuilder().setOptionalString("foo")) .build()) .setNonEmptyMessageOfOtherType( OtherTestMessageLite3.newBuilder().setOptionalInt(3).build()) .setDefaultInstance(TestMessageLite3.newBuilder().buildPartial()) .setDefaultInstanceOfOtherType(OtherTestMessageLite3.newBuilder().buildPartial()) .build(); return ImmutableList.of( new Object[] {"Proto 2", proto2Config}, new Object[] {"Proto 3", proto3Config}); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
data
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
private LiteProtoSubject expectThat(@Nullable MessageLite m) { return expect.about(LiteProtoTruth.liteProtos()).that(m); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
expectThat
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
private Subject expectThat(@Nullable Object o) { return expect.that(o); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
expectThat
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Test public void testSubjectMethods() { expectThat(config.nonEmptyMessage()).isSameInstanceAs(config.nonEmptyMessage()); expectThat(config.nonEmptyMessage().toBuilder()).isNotSameInstanceAs(config.nonEmptyMessage()); expectThat(config.nonEmptyMessage()).isInstanceOf(MessageLite.class); expectThat(config.nonEmptyMessage().toBuilder()).isInstanceOf(MessageLite.Builder.class); expectThat(config.nonEmptyMessage()).isNotInstanceOf(MessageLite.Builder.class); expectThat(config.nonEmptyMessage().toBuilder()).isNotInstanceOf(MessageLite.class); expectThat(config.nonEmptyMessage()).isIn(Arrays.asList(config.nonEmptyMessage())); expectThat(config.nonEmptyMessage()) .isNotIn(Arrays.asList(config.nonEmptyMessageOfOtherValue())); expectThat(config.nonEmptyMessage()) .isAnyOf(config.nonEmptyMessage(), config.nonEmptyMessageOfOtherValue()); expectThat(config.nonEmptyMessage()) .isNoneOf(config.nonEmptyMessageOfOtherValue(), config.nonEmptyMessageOfOtherType()); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
testSubjectMethods
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Test public void testIsEqualTo_success() { expectThat(null).isEqualTo(null); expectThat(null).isNull(); expectThat(config.nonEmptyMessage()).isEqualTo(config.nonEmptyMessage()); expectThat(config.nonEmptyMessage()).isEqualTo(config.equivalentNonEmptyMessage()); expectThat(config.nonEmptyMessage()).isNotEqualTo(config.nonEmptyMessage().toBuilder()); assertThat(config.defaultInstance()).isNotEqualTo(config.defaultInstanceOfOtherType()); assertThat(config.nonEmptyMessage()).isNotEqualTo(config.nonEmptyMessageOfOtherType()); assertThat(config.nonEmptyMessage()).isNotEqualTo(config.nonEmptyMessageOfOtherValue()); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
testIsEqualTo_success
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Test public void testIsEqualTo_failure() { AssertionError e = expectFailure( whenTesting -> whenTesting .that(config.nonEmptyMessage()) .isEqualTo(config.nonEmptyMessageOfOtherValue())); expectRegex(e, ".*expected:.*\"foo\".*"); expectNoRegex(e, ".*but was:.*\"foo\".*"); e = expectFailure( whenTesting -> whenTesting .that(config.nonEmptyMessage()) .isEqualTo(config.nonEmptyMessageOfOtherType())); assertThat(e) .factKeys() .containsExactly("expected", "an instance of", "but was", "an instance of") .inOrder(); e = expectFailure( whenTesting -> whenTesting .that(config.nonEmptyMessage()) .isNotEqualTo(config.equivalentNonEmptyMessage())); expectRegex( e, String.format( "Not true that protos are different\\.\\s*Both are \\(%s\\) <.*optional_int: 3.*>\\.", Pattern.quote(config.nonEmptyMessage().getClass().getName()))); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
testIsEqualTo_failure
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Test public void testHasAllRequiredFields_success() { expectThat(config.nonEmptyMessage()).hasAllRequiredFields(); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
testHasAllRequiredFields_success
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Test public void testHasAllRequiredFields_failures() { if (!config.messageWithoutRequiredFields().isPresent()) { return; } AssertionError e = expectFailure( whenTesting -> whenTesting .that(config.messageWithoutRequiredFields().get()) .hasAllRequiredFields()); expectRegex( e, "expected to have all required fields set\\s*but was: .*\\(Lite runtime could not" + " determine which fields were missing.\\)"); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
testHasAllRequiredFields_failures
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Test public void testDefaultInstance_success() { expectThat(config.defaultInstance()).isEqualToDefaultInstance(); expectThat(config.defaultInstanceOfOtherType()).isEqualToDefaultInstance(); expectThat(config.nonEmptyMessage().getDefaultInstanceForType()).isEqualToDefaultInstance(); expectThat(null).isNotEqualToDefaultInstance(); expectThat(config.nonEmptyMessage()).isNotEqualToDefaultInstance(); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
testDefaultInstance_success
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Test public void testDefaultInstance_failure() { AssertionError e = expectFailure( whenTesting -> whenTesting.that(config.nonEmptyMessage()).isEqualToDefaultInstance()); expectRegex( e, "Not true that <.*optional_int:\\s*3.*> is a default proto instance\\.\\s*" + "It has set values\\."); e = expectFailure( whenTesting -> whenTesting.that(config.defaultInstance()).isNotEqualToDefaultInstance()); expectRegex( e, String.format( "Not true that \\(%s\\) <.*\\[empty proto\\].*> is not a default " + "proto instance\\.\\s*It has no set values\\.", Pattern.quote(config.defaultInstance().getClass().getName()))); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
testDefaultInstance_failure
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Test public void testSerializedSize_success() { int size = config.nonEmptyMessage().getSerializedSize(); expectThat(config.nonEmptyMessage()).serializedSize().isEqualTo(size); expectThat(config.defaultInstance()).serializedSize().isEqualTo(0); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
testSerializedSize_success
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
@Test public void testSerializedSize_failure() { int size = config.nonEmptyMessage().getSerializedSize(); AssertionError e = expectFailure( whenTesting -> whenTesting.that(config.nonEmptyMessage()).serializedSize().isGreaterThan(size)); assertThat(e).factValue("value of").isEqualTo("liteProto.getSerializedSize()"); assertThat(e).factValue("liteProto was").containsMatch("optional_int:\\s*3"); e = expectFailure( whenTesting -> whenTesting.that(config.defaultInstance()).serializedSize().isGreaterThan(0)); assertThat(e).factValue("value of").isEqualTo("liteProto.getSerializedSize()"); assertThat(e).factValue("liteProto was").contains("[empty proto]"); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
testSerializedSize_failure
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
private void expectRegex(AssertionError e, String regex) { expect.that(e).hasMessageThat().matches(Pattern.compile(regex, Pattern.DOTALL)); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
expectRegex
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
private void expectNoRegex(AssertionError e, String regex) { expect.that(e).hasMessageThat().doesNotMatch(Pattern.compile(regex, Pattern.DOTALL)); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
expectNoRegex
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
private static AssertionError expectFailure( SimpleSubjectBuilderCallback<LiteProtoSubject, MessageLite> assertionCallback) { return expectFailureAbout(liteProtos(), assertionCallback); }
We run (almost) all the tests for both proto2 and proto3 implementations. This class organizes the parameters much more cleanly than a raw Object[].
expectFailure
java
google/truth
extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
https://github.com/google/truth/blob/master/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java
Apache-2.0
static FieldDescriptor typeUrlFieldDescriptor() { return TYPE_URL_FIELD_DESCRIPTOR; }
Helper methods for working with Any protos.
typeUrlFieldDescriptor
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
Apache-2.0
static SubScopeId typeUrlSubScopeId() { return TYPE_URL_SUB_SCOPE_ID; }
Helper methods for working with Any protos.
typeUrlSubScopeId
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
Apache-2.0
static FieldDescriptor valueFieldDescriptor() { return VALUE_FIELD_DESCRIPTOR; }
Helper methods for working with Any protos.
valueFieldDescriptor
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
Apache-2.0
static SubScopeId valueSubScopeId() { return VALUE_SUB_SCOPE_ID; }
Helper methods for working with Any protos.
valueSubScopeId
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
Apache-2.0
static TypeRegistry defaultTypeRegistry() { return DEFAULT_TYPE_REGISTRY; }
Helper methods for working with Any protos.
defaultTypeRegistry
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
Apache-2.0
static ExtensionRegistry defaultExtensionRegistry() { return DEFAULT_EXTENSION_REGISTRY; }
Helper methods for working with Any protos.
defaultExtensionRegistry
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
Apache-2.0
static Optional<Message> unpack( Message any, TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) { Preconditions.checkArgument( any.getDescriptorForType().equals(Any.getDescriptor()), "Expected type google.protobuf.Any, but was: %s", any.getDescriptorForType().getFullName()); String typeUrl = (String) any.getField(typeUrlFieldDescriptor()); ByteString value = (ByteString) any.getField(valueFieldDescriptor()); try { Descriptor descriptor = typeRegistry.getDescriptorForTypeUrl(typeUrl); if (descriptor == null) { return Optional.absent(); } Message defaultMessage = DynamicMessage.parseFrom(descriptor, value, extensionRegistry); return Optional.of(defaultMessage); } catch (InvalidProtocolBufferException e) { return Optional.absent(); } }
Unpack an `Any` proto using the given TypeRegistry and ExtensionRegistry.
unpack
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/AnyUtils.java
Apache-2.0
@Memoized Object actualOrExpected() { return actual().or(expected()).get(); }
Returns {@code actual().get()}, or {@code expected().get()}, whichever is available.
actualOrExpected
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Memoized @Override Iterable<? extends RecursableDiffEntity> childEntities() { return ImmutableList.copyOf( Iterables.concat(breakdown().asSet(), unknownsBreakdown().asSet())); }
Returns {@code actual().get()}, or {@code expected().get()}, whichever is available.
childEntities
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Override final void printContents(boolean includeMatches, String fieldPrefix, StringBuilder sb) { if (!includeMatches && isMatched()) { return; } fieldPrefix = newFieldPrefix(fieldPrefix, fieldName()); switch (result()) { case ADDED: sb.append("added: ").append(fieldPrefix).append(": "); if (actual().get() instanceof Message) { sb.append("\n"); printMessage((Message) actual().get(), sb); } else { printFieldValue(subScopeId().get(), actual().get(), sb); sb.append("\n"); } return; case IGNORED: sb.append("ignored: ").append(fieldPrefix).append("\n"); return; case MATCHED: sb.append("matched: ").append(fieldPrefix); if (actualOrExpected() instanceof Message) { sb.append("\n"); printChildContents(includeMatches, fieldPrefix, sb); } else { sb.append(": "); printFieldValue(subScopeId().get(), actualOrExpected(), sb); sb.append("\n"); } return; case MODIFIED: sb.append("modified: ").append(fieldPrefix); if (actualOrExpected() instanceof Message) { sb.append("\n"); printChildContents(includeMatches, fieldPrefix, sb); } else { sb.append(": "); printFieldValue(subScopeId().get(), expected().get(), sb); sb.append(" -> "); printFieldValue(subScopeId().get(), actual().get(), sb); sb.append("\n"); } return; case REMOVED: sb.append("deleted: ").append(fieldPrefix).append(": "); if (expected().get() instanceof Message) { sb.append("\n"); printMessage((Message) expected().get(), sb); } else { printFieldValue(subScopeId().get(), expected().get(), sb); sb.append("\n"); } return; default: throw new AssertionError("Impossible: " + result()); } }
Returns {@code actual().get()}, or {@code expected().get()}, whichever is available.
printContents
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Override final boolean isContentEmpty() { return false; }
Returns {@code actual().get()}, or {@code expected().get()}, whichever is available.
isContentEmpty
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
static SingularField ignored(String fieldName) { return newBuilder() .setFieldName(fieldName) .setResult(Result.IGNORED) // Ignored fields don't need a customized proto printer. .setProtoPrinter(TextFormat.printer()) .build(); }
Returns {@code actual().get()}, or {@code expected().get()}, whichever is available.
ignored
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
static Builder newBuilder() { return new AutoValue_DiffResult_SingularField.Builder(); }
Returns {@code actual().get()}, or {@code expected().get()}, whichever is available.
newBuilder
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Memoized @Override Iterable<? extends RecursableDiffEntity> childEntities() { return breakdown().asSet(); }
A detailed breakdown of the comparison between the messages. Present iff {@code actual()} and {@code expected()} are {@link Message}s.
childEntities
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Memoized boolean isMessage() { return actual().orNull() instanceof Message || expected().orNull() instanceof Message; }
Returns true if actual() and expected() contain Message types.
isMessage
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
private static String indexed(String fieldPrefix, Optional<Integer> fieldIndex) { String index = fieldIndex.isPresent() ? fieldIndex.get().toString() : "?"; return fieldPrefix + "[" + index + "]"; }
Returns true if actual() and expected() contain Message types.
indexed
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Override final void printContents(boolean includeMatches, String fieldPrefix, StringBuilder sb) { printContentsForRepeatedField( /* includeSelfAlways = */ false, includeMatches, fieldPrefix, sb); }
Returns true if actual() and expected() contain Message types.
printContents
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
final void printContentsForRepeatedField( boolean includeSelfAlways, boolean includeMatches, String fieldPrefix, StringBuilder sb) { if (!includeSelfAlways && !includeMatches && isMatched()) { return; } switch (result()) { case ADDED: sb.append("added: ").append(indexed(fieldPrefix, actualFieldIndex())).append(": "); if (isMessage()) { sb.append("\n"); printMessage((Message) actual().get(), sb); } else { printFieldValue(fieldDescriptor(), actual().get(), sb); sb.append("\n"); } return; case IGNORED: sb.append("ignored: "); if (actualFieldIndex().equals(expectedFieldIndex())) { sb.append(indexed(fieldPrefix, actualFieldIndex())); } else { sb.append(indexed(fieldPrefix, expectedFieldIndex())) .append(" -> ") .append(indexed(fieldPrefix, actualFieldIndex())); } // We output the message contents for ignored pair results, since it's likely not clear // from the index alone why they were ignored. sb.append(":"); if (isMessage()) { sb.append("\n"); printChildContents(includeMatches, indexed(fieldPrefix, actualFieldIndex()), sb); } else { sb.append(" "); printFieldValue(fieldDescriptor(), actual().get(), sb); sb.append("\n"); } return; case MATCHED: if (actualFieldIndex().get().equals(expectedFieldIndex().get())) { sb.append("matched: ").append(indexed(fieldPrefix, actualFieldIndex())); } else { sb.append("moved: ") .append(indexed(fieldPrefix, expectedFieldIndex())) .append(" -> ") .append(indexed(fieldPrefix, actualFieldIndex())); } sb.append(":"); if (isMessage()) { sb.append("\n"); printChildContents(includeMatches, indexed(fieldPrefix, actualFieldIndex()), sb); } else { sb.append(" "); printFieldValue(fieldDescriptor(), actual().get(), sb); sb.append("\n"); } return; case MOVED_OUT_OF_ORDER: sb.append("out_of_order: ") .append(indexed(fieldPrefix, expectedFieldIndex())) .append(" -> ") .append(indexed(fieldPrefix, actualFieldIndex())); sb.append(":"); if (isMessage()) { sb.append("\n"); printChildContents(includeMatches, indexed(fieldPrefix, actualFieldIndex()), sb); } else { sb.append(" "); printFieldValue(fieldDescriptor(), actual().get(), sb); sb.append("\n"); } return; case MODIFIED: sb.append("modified: "); if (actualFieldIndex().get().equals(expectedFieldIndex().get())) { sb.append(indexed(fieldPrefix, actualFieldIndex())); } else { sb.append(indexed(fieldPrefix, expectedFieldIndex())) .append(" -> ") .append(indexed(fieldPrefix, actualFieldIndex())); } sb.append(":"); if (isMessage()) { sb.append("\n"); printChildContents(includeMatches, indexed(fieldPrefix, actualFieldIndex()), sb); } else { sb.append(" "); printFieldValue(fieldDescriptor(), expected().get(), sb); sb.append(" -> "); printFieldValue(fieldDescriptor(), actual().get(), sb); } return; case REMOVED: sb.append("deleted: ").append(indexed(fieldPrefix, expectedFieldIndex())).append(": "); if (isMessage()) { sb.append("\n"); printMessage((Message) expected().get(), sb); } else { printFieldValue(fieldDescriptor(), expected().get(), sb); sb.append("\n"); } return; } throw new AssertionError("Impossible: " + result()); }
Returns true if actual() and expected() contain Message types.
printContentsForRepeatedField
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Override final boolean isContentEmpty() { return false; }
Returns true if actual() and expected() contain Message types.
isContentEmpty
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
static Builder newBuilder() { return new AutoValue_DiffResult_RepeatedField_PairResult.Builder(); }
Returns true if actual() and expected() contain Message types.
newBuilder
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Memoized @Override Iterable<? extends RecursableDiffEntity> childEntities() { return pairResults(); }
Pairs of elements which were diffed against each other.
childEntities
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Override final void printContents(boolean includeMatches, String fieldPrefix, StringBuilder sb) { fieldPrefix = newFieldPrefix(fieldPrefix, fieldDescriptor().getName()); for (PairResult pairResult : pairResults()) { pairResult.printContentsForRepeatedField( /* includeSelfAlways = */ !isMatched(), includeMatches, fieldPrefix, sb); } }
Pairs of elements which were diffed against each other.
printContents
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@Override final boolean isContentEmpty() { return pairResults().isEmpty(); }
Pairs of elements which were diffed against each other.
isContentEmpty
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
static Builder newBuilder() { return new AutoValue_DiffResult_RepeatedField.Builder(); }
Pairs of elements which were diffed against each other.
newBuilder
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0
@CanIgnoreReturnValue final Builder addPairResult(PairResult pairResult) { pairResultsBuilder().add(pairResult); return this; }
Pairs of elements which were diffed against each other.
addPairResult
java
google/truth
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
https://github.com/google/truth/blob/master/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/DiffResult.java
Apache-2.0