aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java')
-rw-r--r--core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java39
1 files changed, 26 insertions, 13 deletions
diff --git a/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java b/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
index 854afb06..224bf653 100644
--- a/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
+++ b/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java
@@ -18,7 +18,10 @@ package com.google.common.truth.extension;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Truth.assertAbout;
+import com.google.common.truth.ComparableSubject;
import com.google.common.truth.FailureMetadata;
+import com.google.common.truth.LongSubject;
+import com.google.common.truth.StringSubject;
import com.google.common.truth.Subject;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -31,18 +34,14 @@ public final class EmployeeSubject extends Subject {
// User-defined entry point
public static EmployeeSubject assertThat(@Nullable Employee employee) {
- return assertAbout(EMPLOYEE_SUBJECT_FACTORY).that(employee);
+ return assertAbout(employees()).that(employee);
}
// Static method for getting the subject factory (for use with assertAbout())
public static Subject.Factory<EmployeeSubject, Employee> employees() {
- return EMPLOYEE_SUBJECT_FACTORY;
+ return EmployeeSubject::new;
}
- // Boiler-plate Subject.Factory for EmployeeSubject
- private static final Subject.Factory<EmployeeSubject, Employee> EMPLOYEE_SUBJECT_FACTORY =
- EmployeeSubject::new;
-
private final Employee actual;
private EmployeeSubject(FailureMetadata failureMetadata, @Nullable Employee subject) {
@@ -53,19 +52,19 @@ public final class EmployeeSubject extends Subject {
// User-defined test assertion SPI below this point
public void hasName(String name) {
- check("name()").that(actual.name()).isEqualTo(name);
+ name().isEqualTo(name);
}
public void hasUsername(String username) {
- check("username()").that(actual.username()).isEqualTo(username);
+ username().isEqualTo(username);
}
public void hasId(long id) {
- check("id()").that(actual.id()).isEqualTo(id);
+ id().isEqualTo(id);
}
public void hasLocation(Employee.Location location) {
- check("location()").that(actual.location()).isEqualTo(location);
+ location().isEqualTo(location);
}
public void isCeo() {
@@ -80,7 +79,21 @@ public final class EmployeeSubject extends Subject {
}
}
- // TODO(kak): Add methods that return other subjects. E.g.,
- // public StringSubject username() {}
- // public IterableSubject languages() {}
+ // Chained subjects methods below this point
+
+ public StringSubject name() {
+ return check("name()").that(actual.name());
+ }
+
+ public StringSubject username() {
+ return check("username()").that(actual.username());
+ }
+
+ public LongSubject id() {
+ return check("id()").that(actual.id());
+ }
+
+ public ComparableSubject<Employee.Location> location() {
+ return check("location()").that(actual.location());
+ }
}