-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy the *Verb* types to *SubjectBuilder*, and deprecate the old types.
Additionally, make TestVerb (now StandardSubjectBuilder) and its supertypes non-extensible. Finally, add a bunch of docs. This CL leaves SubjectFactory as a top-level type (and introduces CustomSubjectBuilderFactory as a top-level type). This is so that I can introduce the nested types with a different parameter type ("FailureBuilder" or something like that) as part of a later step. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=166715211
- Loading branch information
Showing
23 changed files
with
973 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/src/main/java/com/google/common/truth/CustomSubjectBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2016 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.common.truth; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* In a fluent assertion chain, exposes one or more "custom" {@code that} methods, which accept a | ||
* value under test and return a {@link Subject}. | ||
* | ||
* <p>(Note that the "custom" {@code that} methods are not defined on {@code CustomSubjectBuilder} | ||
* itself, only on its subtypes, which are the types users actually interact with.) | ||
* | ||
* <p>TODO(cpovirk): Link to a doc about the full assertion chain. | ||
* | ||
* <h2>For people extending Truth</h2> | ||
* | ||
* <p>TODO(cpovirk): Link to a doc about custom subjects. | ||
*/ | ||
public abstract class CustomSubjectBuilder { | ||
private final FailureStrategy failureStrategy; | ||
|
||
protected CustomSubjectBuilder(FailureStrategy failureStrategy) { | ||
this.failureStrategy = checkNotNull(failureStrategy); | ||
} | ||
|
||
protected final FailureStrategy failureStrategy() { | ||
return failureStrategy; | ||
} | ||
|
||
// TODO(user,cgruber): Better enforce that subclasses implement a that() method. | ||
} |
34 changes: 34 additions & 0 deletions
34
core/src/main/java/com/google/common/truth/CustomSubjectBuilderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2016 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.common.truth; | ||
|
||
/** | ||
* In a fluent assertion chain, the argument to the "custom" overload of {@link | ||
* StandardSubjectBuilder#about(CustomSubjectBuilderFactory) about}, the method that specifies what | ||
* kind of {@link Subject} to create. | ||
* | ||
* <p>TODO(cpovirk): Link to a doc about the full assertion chain. | ||
* | ||
* <h2>For people extending Truth</h2> | ||
* | ||
* <p>TODO(cpovirk): Link to a doc about custom subjects. | ||
*/ | ||
// TODO(cpovirk): Convert to a nested type when changing FailureStrategy parameter to another type. | ||
public interface CustomSubjectBuilderFactory<CustomSubjectBuilderT extends CustomSubjectBuilder> { | ||
/** Creates a new {@link CustomSubjectBuilder} of the appropriate type. */ | ||
CustomSubjectBuilderT createSubjectBuilder(FailureStrategy failureStrategy); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.