Skip to content

Commit

Permalink
Add some missing checkNotNulls to Truth.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=108703183
  • Loading branch information
kluever authored and cpovirk committed Nov 30, 2015
1 parent ac32806 commit ec55f55
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
13 changes: 7 additions & 6 deletions core/src/main/java/com/google/common/truth/AbstractVerb.java
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.common.truth;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.StringUtil.format;

import javax.annotation.CheckReturnValue;
Expand All @@ -24,7 +25,7 @@ public abstract class AbstractVerb<T extends AbstractVerb<T>> {
private final FailureStrategy failureStrategy;

public AbstractVerb(FailureStrategy failureStrategy) {
this.failureStrategy = failureStrategy;
this.failureStrategy = checkNotNull(failureStrategy);
}

protected FailureStrategy getFailureStrategy() {
Expand Down Expand Up @@ -87,9 +88,9 @@ public static class DelegatedVerb<S extends Subject<S, T>, T> {
private final SubjectFactory<S, T> factory;
private final FailureStrategy failureStrategy;

public DelegatedVerb(FailureStrategy fs, SubjectFactory<S, T> factory) {
this.factory = factory;
this.failureStrategy = fs;
public DelegatedVerb(FailureStrategy failureStrategy, SubjectFactory<S, T> factory) {
this.factory = checkNotNull(factory);
this.failureStrategy = checkNotNull(failureStrategy);
}

@CheckReturnValue
Expand All @@ -103,8 +104,8 @@ protected static class MessagePrependingFailureStrategy extends FailureStrategy
private final AbstractVerb<?> verb;

protected MessagePrependingFailureStrategy(FailureStrategy delegate, AbstractVerb<?> verb) {
this.delegate = delegate;
this.verb = verb;
this.delegate = checkNotNull(delegate);
this.verb = checkNotNull(verb);
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/com/google/common/truth/Expect.java
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.common.truth;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.StringUtil.messageFor;

import com.google.auto.value.AutoValue;
Expand Down Expand Up @@ -47,7 +48,7 @@ public ExpectationGatherer(boolean showStackTrace) {

@Override
public void fail(String message) {
fail(message, new Throwable(message));
fail(checkNotNull(message), new Throwable(message));
}

@Override
Expand Down Expand Up @@ -126,7 +127,7 @@ public static Expect createAndEnableStackTrace() {

Expect(ExpectationGatherer gatherer) {
super(gatherer);
this.gatherer = gatherer;
this.gatherer = checkNotNull(gatherer);
}

public boolean hasFailures() {
Expand All @@ -145,6 +146,8 @@ protected FailureStrategy getFailureStrategy() {
// TODO(cgruber): Make this override TestRule when 4.9 is released.
@Override
public Statement apply(final Statement base, Description description) {
checkNotNull(base);
checkNotNull(description);
return new Statement() {
@Override
public void evaluate() throws Throwable {
Expand Down
8 changes: 7 additions & 1 deletion core/src/main/java/com/google/common/truth/StringUtil.java
Expand Up @@ -15,6 +15,8 @@
*/
package com.google.common.truth;

import static com.google.common.base.Preconditions.checkNotNull;

import javax.annotation.Nullable;

/**
Expand All @@ -31,7 +33,11 @@ private StringUtil() {}
* TODO(cgruber): Do something closer to what JUnit's {@code ComparisonFailure} does.
*/
static String messageFor(String message, CharSequence expected, CharSequence actual) {
return message + "\n\nExpected:\n" + expected + "\n\nActual:\n" + actual;
return checkNotNull(message)
+ "\n\nExpected:\n"
+ checkNotNull(expected)
+ "\n\nActual:\n"
+ checkNotNull(actual);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/google/common/truth/TestVerb.java
Expand Up @@ -47,7 +47,7 @@ public TestVerb(FailureStrategy failureStrategy, @Nullable String format) {

public TestVerb(
FailureStrategy failureStrategy, @Nullable String format, @Nullable Object... args) {
super(failureStrategy);
super(checkNotNull(failureStrategy));
this.format = format;
this.args = checkNotNull(args);

Expand Down

0 comments on commit ec55f55

Please sign in to comment.