Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create ProtoTruth and LiteProtoTruth utility classes, and deprecate t…
…he original factories. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=135520761
- Loading branch information
1 parent
a9240a4
commit 80f6b87
Showing
9 changed files
with
129 additions
and
14 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
48 changes: 48 additions & 0 deletions
48
...ions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
/* | |||
* 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.extensions.proto; | |||
|
|||
import static com.google.common.truth.Truth.assertAbout; | |||
|
|||
import com.google.common.truth.AbstractVerb; | |||
import com.google.common.truth.SubjectFactory; | |||
import com.google.protobuf.MessageLite; | |||
import javax.annotation.Nullable; | |||
|
|||
/** | |||
* 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 {@link ProtoTruth} provides, so if you are already | |||
* {@link ProtoTruth}, you should not import this class. {@code LiteProtoTruth} is only useful if | |||
* you cannot depend on {@link ProtoTruth} for dependency management reasons. | |||
* | |||
* <p>Note: Usage of different failure strategies such as <em>assume</em> and <em>expect</em> should | |||
* rely on {@link AbstractVerb#about(SubjectFactory)} to begin a chain with those alternative | |||
* behaviors. | |||
*/ | |||
public final class LiteProtoTruth { | |||
public static LiteProtoSubject<?, MessageLite> assertThat(@Nullable MessageLite messageLite) { | |||
return assertAbout(liteProtos()).that(messageLite); | |||
} | |||
|
|||
public static LiteProtoSubject.Factory<?, MessageLite> liteProtos() { | |||
return LiteProtoSubject.liteProtos(); | |||
} | |||
|
|||
private LiteProtoTruth() {} | |||
} |
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
60 changes: 60 additions & 0 deletions
60
extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
/* | |||
* 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.extensions.proto; | |||
|
|||
import static com.google.common.truth.Truth.assertAbout; | |||
|
|||
import com.google.common.truth.AbstractVerb; | |||
import com.google.common.truth.SubjectFactory; | |||
import com.google.protobuf.Message; | |||
import com.google.protobuf.MessageLite; | |||
import javax.annotation.Nullable; | |||
|
|||
/** | |||
* A set of static methods to begin a Truth assertion chain for protocol buffers. | |||
* | |||
* <p>Note: Usage of different failure strategies such as <em>assume</em> and <em>expect</em> should | |||
* rely on {@link AbstractVerb#about(SubjectFactory)} to begin a chain with those alternative | |||
* behaviors. | |||
*/ | |||
public final class ProtoTruth { | |||
////////////////////////////////////////////////////////////////////////////////////////////////// | |||
// assertThat() overloads. | |||
////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
|||
public static LiteProtoSubject<?, MessageLite> assertThat(@Nullable MessageLite messageLite) { | |||
return assertAbout(liteProtos()).that(messageLite); | |||
} | |||
|
|||
public static ProtoSubject<?, Message> assertThat(@Nullable Message message) { | |||
return assertAbout(protos()).that(message); | |||
} | |||
|
|||
////////////////////////////////////////////////////////////////////////////////////////////////// | |||
// SubjectFactory factories. | |||
////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
|||
public static ProtoSubject.Factory<?, Message> protos() { | |||
return ProtoSubject.protos(); | |||
} | |||
|
|||
public static LiteProtoSubject.Factory<?, MessageLite> liteProtos() { | |||
return LiteProtoSubject.liteProtos(); | |||
} | |||
|
|||
private ProtoTruth() {} | |||
} |
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
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