1
1
package com .team2813 .lib2813 .limelight .truth ;
2
2
3
- import com .google .common .truth .DoubleSubject ;
4
3
import com .google .common .truth .FailureMetadata ;
5
4
import com .google .common .truth .Subject ;
6
5
import edu .wpi .first .math .geometry .Pose3d ;
7
- import edu .wpi .first .math .geometry .Rotation3d ;
8
- import edu .wpi .first .math .geometry .Translation3d ;
9
6
10
7
import javax .annotation .Nullable ;
11
8
18
15
* <p>See <a href="https://truth.dev/extension">Writing your own custom subject</a>
19
16
* to learn about creating custom Truth subjects.
20
17
*/
21
- public class Pose3dSubject extends Subject {
18
+ public final class Pose3dSubject extends Subject {
22
19
23
20
// User-defined entry point
24
21
public static Pose3dSubject assertThat (@ Nullable Pose3d pose ) {
@@ -32,7 +29,7 @@ public static Subject.Factory<Pose3dSubject, Pose3d> pose3ds() {
32
29
33
30
private final Pose3d actual ;
34
31
35
- protected Pose3dSubject (FailureMetadata failureMetadata , @ Nullable Pose3d subject ) {
32
+ private Pose3dSubject (FailureMetadata failureMetadata , @ Nullable Pose3d subject ) {
36
33
super (failureMetadata , subject );
37
34
this .actual = subject ;
38
35
}
@@ -68,141 +65,4 @@ private Pose3d nonNullActualPose() {
68
65
return actual ;
69
66
}
70
67
71
- /** Truth Subject for making assertions about {@link Translation3d} values. */
72
- public static class Translation3dSubject extends Subject {
73
-
74
- // User-defined entry point
75
- public static Translation3dSubject assertThat (@ Nullable Translation3d translation ) {
76
- return assertAbout (translation3ds ()).that (translation );
77
- }
78
-
79
- // Static method for getting the subject factory (for use with assertAbout())
80
- public static Factory <Translation3dSubject , Translation3d > translation3ds () {
81
- return Translation3dSubject ::new ;
82
- }
83
-
84
- private final Translation3d actual ;
85
-
86
- private Translation3dSubject (FailureMetadata failureMetadata , @ Nullable Translation3d subject ) {
87
- super (failureMetadata , subject );
88
- this .actual = subject ;
89
- }
90
-
91
- // User-defined test assertion SPI below this point
92
-
93
- public TolerantComparison <Translation3d > isWithin (double tolerance ) {
94
- return new TolerantComparison <Translation3d >() {
95
- @ Override
96
- public void of (Translation3d expected ) {
97
- x ().isWithin (tolerance ).of (expected .getX ());
98
- y ().isWithin (tolerance ).of (expected .getY ());
99
- z ().isWithin (tolerance ).of (expected .getZ ());
100
- }
101
- };
102
- }
103
-
104
- public void isZero () {
105
- if (!Translation3d .kZero .equals (actual )) {
106
- failWithActual (simpleFact ("expected to be zero" ));
107
- }
108
- }
109
-
110
- // Chained subjects methods below this point
111
-
112
- public DoubleSubject x () {
113
- return check ("getX()" ).that (nonNullActual ().getX ());
114
- }
115
-
116
- public DoubleSubject y () {
117
- return check ("getY()" ).that (nonNullActual ().getY ());
118
- }
119
-
120
- public DoubleSubject z () {
121
- return check ("getZ()" ).that (nonNullActual ().getZ ());
122
- }
123
-
124
- // Helper methods below this point
125
-
126
- private Translation3d nonNullActual () {
127
- if (actual == null ) {
128
- failWithActual (simpleFact ("expected a non-null Translation3d" ));
129
- }
130
- return actual ;
131
- }
132
- }
133
-
134
- /** Truth Subject for making assertions about {@link Rotation3d} values. */
135
- static class Rotation3dSubject extends Subject {
136
- // User-defined entry point
137
- public static Rotation3dSubject assertThat (@ Nullable Rotation3d rotation ) {
138
- return assertAbout (rotation3ds ()).that (rotation );
139
- }
140
-
141
- // Static method for getting the subject factory (for use with assertAbout())
142
- public static Factory <Rotation3dSubject , Rotation3d > rotation3ds () {
143
- return Rotation3dSubject ::new ;
144
- }
145
-
146
- private final Rotation3d actual ;
147
-
148
- private Rotation3dSubject (FailureMetadata failureMetadata , @ Nullable Rotation3d subject ) {
149
- super (failureMetadata , subject );
150
- this .actual = subject ;
151
- }
152
-
153
- // User-defined test assertion SPI below this point
154
-
155
- public TolerantComparison <Rotation3d > isWithin (double tolerance ) {
156
- return new TolerantComparison <Rotation3d >() {
157
- @ Override
158
- public void of (Rotation3d expected ) {
159
- x ().isWithin (tolerance ).of (expected .getX ());
160
- y ().isWithin (tolerance ).of (expected .getY ());
161
- z ().isWithin (tolerance ).of (expected .getZ ());
162
- }
163
- };
164
- }
165
-
166
- public void isZero () {
167
- if (!Rotation3d .kZero .equals (actual )) {
168
- failWithActual (simpleFact ("expected to be zero" ));
169
- }
170
- }
171
-
172
- // Chained subjects methods below this point
173
-
174
- public DoubleSubject x () {
175
- return check ("getX()" ).that (nonNullActual ().getX ());
176
- }
177
-
178
- public DoubleSubject y () {
179
- return check ("getY()" ).that (nonNullActual ().getY ());
180
- }
181
-
182
- public DoubleSubject z () {
183
- return check ("getZ()" ).that (nonNullActual ().getZ ());
184
- }
185
-
186
- // Helper methods below this point
187
-
188
- private Rotation3d nonNullActual () {
189
- if (actual == null ) {
190
- failWithActual (simpleFact ("expected a non-null Rotation3d" ));
191
- }
192
- return actual ;
193
- }
194
- }
195
-
196
- /**
197
- * A partially specified check about an approximate relationship to a {@code double} subject using
198
- * a tolerance.
199
- */
200
- public interface TolerantComparison <T > {
201
-
202
- /**
203
- * Fails if the subject was expected to be within the tolerance of the given value but was not.
204
- * The subject and tolerance are specified earlier in the fluent call chain.
205
- */
206
- void of (T expected );
207
- }
208
68
}
0 commit comments