Skip to content

Commit

Permalink
Replace truth.FailureStrategy with truth.FailureMetadata in custom Su…
Browse files Browse the repository at this point in the history
…bjects.

Also changed truth.SubjectFactory to truth.Subject.Factory (plain renaming) and use method reference instead of anonymous class to create the factory when applicable.

FailureMetadata, an opaque object to its users, is introduced to replace FailureStrategy in in custom Subject in order to resolve some existing flaws of FailureStrategy as well as enable new features to be added to Truth.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=171351528
  • Loading branch information
JiangJi authored and cushon committed Oct 14, 2017
1 parent f08e656 commit e29e5dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
Expand Up @@ -24,9 +24,8 @@
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.truth.FailureStrategy;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import com.google.errorprone.BugCheckerInfo;
import com.google.errorprone.BugPattern.SeverityLevel;
import com.google.errorprone.ErrorProneJavaCompilerTest;
Expand Down Expand Up @@ -456,8 +455,8 @@ public void allChecksAsWarningsWorks() throws Exception {

private static class ScannerSupplierSubject
extends Subject<ScannerSupplierSubject, ScannerSupplier> {
ScannerSupplierSubject(FailureStrategy failureStrategy, ScannerSupplier scannerSupplier) {
super(failureStrategy, scannerSupplier);
ScannerSupplierSubject(FailureMetadata failureMetadata, ScannerSupplier scannerSupplier) {
super(failureMetadata, scannerSupplier);
}

final void hasSeverities(Map<String, SeverityLevel> severities) {
Expand All @@ -476,12 +475,6 @@ private ScannerSupplierSubject assertScanner(ScannerSupplier scannerSupplier) {
return assertAbout(SCANNER_SUBJECT_FACTORY).that(scannerSupplier);
}

private static final SubjectFactory<ScannerSupplierSubject, ScannerSupplier>
SCANNER_SUBJECT_FACTORY =
new SubjectFactory<ScannerSupplierSubject, ScannerSupplier>() {
@Override
public ScannerSupplierSubject getSubject(FailureStrategy fs, ScannerSupplier t) {
return new ScannerSupplierSubject(fs, t);
}
};
private static final Subject.Factory<ScannerSupplierSubject, ScannerSupplier>
SCANNER_SUBJECT_FACTORY = ScannerSupplierSubject::new;
}
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -33,7 +33,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<guava.version>21.0</guava.version>
<truth.version>0.31</truth.version>
<truth.version>0.36</truth.version>
<javac.version>9-dev-r4023-3</javac.version>
<autovalue.version>1.3</autovalue.version>
<junit.version>4.13-SNAPSHOT</junit.version>
Expand Down

0 comments on commit e29e5dd

Please sign in to comment.