Skip to content

Commit 9247663

Browse files
committed
Instead of calling Subject.actual(), store the actual value in a field, and read that.
actual() is being removed. While there, upgrade to Truth 0.44. The upgade isn't necessary for the actual() migration, but it should reduce the chance that we end up using other methods that are later removed.
1 parent bd52865 commit 9247663

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

contrib/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>com.google.truth</groupId>
2424
<artifactId>truth</artifactId>
25-
<version>0.37</version>
25+
<version>0.44</version>
2626
</dependency>
2727
<!-- Metrics library -->
2828
<dependency>
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>com.google.truth.extensions</groupId>
3838
<artifactId>truth-java8-extension</artifactId>
39-
<version>0.37</version>
39+
<version>0.44</version>
4040
<scope>test</scope>
4141
</dependency>
4242
<!-- JUnit backport -->

contrib/src/main/java/com/google/monitoring/metrics/contrib/AbstractMetricSubject.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ And<S> andChainer() {
7373
Joiner.on(':').join(metricPoint.labelValues()),
7474
getMessageRepresentation(metricPoint.value()));
7575

76+
private final Metric<T> actual;
77+
7678
protected AbstractMetricSubject(FailureMetadata metadata, Metric<T> actual) {
7779
super(metadata, checkNotNull(actual));
80+
this.actual = actual;
7881
}
7982

8083
/**
@@ -84,7 +87,7 @@ protected AbstractMetricSubject(FailureMetadata metadata, Metric<T> actual) {
8487
*/
8588
@Override
8689
public String actualCustomStringRepresentation() {
87-
return actual().getMetricSchema().name();
90+
return actual.getMetricSchema().name();
8891
}
8992

9093
/**
@@ -102,7 +105,7 @@ public And<S> hasValueForLabels(T value, String... labels) {
102105
Joiner.on(':').join(labels),
103106
"has labeled values",
104107
Lists.transform(
105-
Ordering.<MetricPoint<T>>natural().sortedCopy(actual().getTimestampedValues()),
108+
Ordering.<MetricPoint<T>>natural().sortedCopy(actual.getTimestampedValues()),
106109
metricPointConverter));
107110
}
108111
if (!metricPoint.value().equals(value)) {
@@ -130,7 +133,7 @@ public And<S> hasAnyValueForLabels(String... labels) {
130133
Joiner.on(':').join(labels),
131134
"has labeled values",
132135
Lists.transform(
133-
Ordering.<MetricPoint<T>>natural().sortedCopy(actual().getTimestampedValues()),
136+
Ordering.<MetricPoint<T>>natural().sortedCopy(actual.getTimestampedValues()),
134137
metricPointConverter));
135138
}
136139
if (hasDefaultValue(metricPoint)) {
@@ -162,15 +165,15 @@ protected And<S> doesNotHaveAnyValueForLabels(String... labels) {
162165
* has already been made.
163166
*/
164167
public And<S> hasNoOtherValues() {
165-
for (MetricPoint<T> metricPoint : actual().getTimestampedValues()) {
168+
for (MetricPoint<T> metricPoint : actual.getTimestampedValues()) {
166169
if (!expectedNondefaultLabelTuples.contains(metricPoint.labelValues())) {
167170
if (!hasDefaultValue(metricPoint)) {
168171
failWithBadResults(
169172
"has",
170173
"no other nondefault values",
171174
"has labeled values",
172175
Lists.transform(
173-
Ordering.<MetricPoint<T>>natural().sortedCopy(actual().getTimestampedValues()),
176+
Ordering.<MetricPoint<T>>natural().sortedCopy(actual.getTimestampedValues()),
174177
metricPointConverter));
175178
}
176179
return andChainer();
@@ -180,10 +183,10 @@ public And<S> hasNoOtherValues() {
180183
}
181184

182185
private @Nullable MetricPoint<T> findMetricPointForLabels(ImmutableList<String> labels) {
183-
if (actual().getMetricSchema().labels().size() != labels.size()) {
186+
if (actual.getMetricSchema().labels().size() != labels.size()) {
184187
return null;
185188
}
186-
for (MetricPoint<T> metricPoint : actual().getTimestampedValues()) {
189+
for (MetricPoint<T> metricPoint : actual.getTimestampedValues()) {
187190
if (metricPoint.labelValues().equals(labels)) {
188191
return metricPoint;
189192
}

contrib/src/main/java/com/google/monitoring/metrics/contrib/DistributionMetricSubject.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ public static DistributionMetricSubject assertThat(@Nullable Metric<Distribution
5858
return assertAbout(DistributionMetricSubject::new).that(metric);
5959
}
6060

61+
private final Metric<Distribution> actual;
62+
6163
private DistributionMetricSubject(FailureMetadata metadata, Metric<Distribution> actual) {
6264
super(metadata, actual);
65+
this.actual = actual;
6366
}
6467

6568
/**
@@ -111,7 +114,7 @@ protected String getMessageRepresentation(Distribution distribution) {
111114
*/
112115
public And<DistributionMetricSubject> hasDataSetForLabels(
113116
ImmutableSet<? extends Number> dataSet, String... labels) {
114-
ImmutableList<MetricPoint<Distribution>> metricPoints = actual().getTimestampedValues();
117+
ImmutableList<MetricPoint<Distribution>> metricPoints = actual.getTimestampedValues();
115118
if (metricPoints.isEmpty()) {
116119
failWithBadResults(
117120
"has a distribution for labels", Joiner.on(':').join(labels), "has", "no values");

metrics/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>com.google.truth</groupId>
6666
<artifactId>truth</artifactId>
67-
<version>0.37</version>
67+
<version>0.44</version>
6868
<scope>test</scope>
6969
</dependency>
7070
<!-- JUnit backport -->

stackdriver/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<dependency>
5757
<groupId>com.google.truth</groupId>
5858
<artifactId>truth</artifactId>
59-
<version>0.37</version>
59+
<version>0.44</version>
6060
<scope>test</scope>
6161
</dependency>
6262
<!-- JUnit backport -->

0 commit comments

Comments
 (0)