Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 1e14db2

Browse files
authored
Tests: Migrate from is(Not)SameAs to is(Not)SameInstanceAs. (#1870)
1 parent deefac9 commit 1e14db2

24 files changed

Lines changed: 118 additions & 107 deletions

api/src/test/java/io/opencensus/metrics/DoubleCumulativeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public void noopSameAs() {
8484
DoubleCumulative doubleCumulative =
8585
DoubleCumulative.newNoopDoubleCumulative(NAME, DESCRIPTION, UNIT, LABEL_KEY);
8686
assertThat(doubleCumulative.getDefaultTimeSeries())
87-
.isSameAs(doubleCumulative.getDefaultTimeSeries());
87+
.isSameInstanceAs(doubleCumulative.getDefaultTimeSeries());
8888
assertThat(doubleCumulative.getDefaultTimeSeries())
89-
.isSameAs(doubleCumulative.getOrCreateTimeSeries(LABEL_VALUES));
89+
.isSameInstanceAs(doubleCumulative.getOrCreateTimeSeries(LABEL_VALUES));
9090
}
9191
}

api/src/test/java/io/opencensus/metrics/DoubleGaugeTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ public void noopRemoveTimeSeries_WithNullLabelValues() {
7979
@Test
8080
public void noopSameAs() {
8181
DoubleGauge doubleGauge = DoubleGauge.newNoopDoubleGauge(NAME, DESCRIPTION, UNIT, LABEL_KEY);
82-
assertThat(doubleGauge.getDefaultTimeSeries()).isSameAs(doubleGauge.getDefaultTimeSeries());
8382
assertThat(doubleGauge.getDefaultTimeSeries())
84-
.isSameAs(doubleGauge.getOrCreateTimeSeries(LABEL_VALUES));
83+
.isSameInstanceAs(doubleGauge.getDefaultTimeSeries());
84+
assertThat(doubleGauge.getDefaultTimeSeries())
85+
.isSameInstanceAs(doubleGauge.getOrCreateTimeSeries(LABEL_VALUES));
8586
}
8687
}

api/src/test/java/io/opencensus/metrics/LongCumulativeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public void noopSameAs() {
8484
LongCumulative longCumulative =
8585
LongCumulative.newNoopLongCumulative(NAME, DESCRIPTION, UNIT, LABEL_KEY);
8686
assertThat(longCumulative.getDefaultTimeSeries())
87-
.isSameAs(longCumulative.getDefaultTimeSeries());
87+
.isSameInstanceAs(longCumulative.getDefaultTimeSeries());
8888
assertThat(longCumulative.getDefaultTimeSeries())
89-
.isSameAs(longCumulative.getOrCreateTimeSeries(LABEL_VALUES));
89+
.isSameInstanceAs(longCumulative.getOrCreateTimeSeries(LABEL_VALUES));
9090
}
9191
}

api/src/test/java/io/opencensus/metrics/LongGaugeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public void noopRemoveTimeSeries_WithNullLabelValues() {
7878
@Test
7979
public void noopSameAs() {
8080
LongGauge longGauge = LongGauge.newNoopLongGauge(NAME, DESCRIPTION, UNIT, LABEL_KEY);
81-
assertThat(longGauge.getDefaultTimeSeries()).isSameAs(longGauge.getDefaultTimeSeries());
81+
assertThat(longGauge.getDefaultTimeSeries()).isSameInstanceAs(longGauge.getDefaultTimeSeries());
8282
assertThat(longGauge.getDefaultTimeSeries())
83-
.isSameAs(longGauge.getOrCreateTimeSeries(LABEL_VALUES));
83+
.isSameInstanceAs(longGauge.getOrCreateTimeSeries(LABEL_VALUES));
8484
}
8585
}

api/src/test/java/io/opencensus/metrics/MetricRegistryTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,27 @@ public void noopAddDerivedDoubleCumulative_NullName() {
115115
@Test
116116
public void noopSameAs() {
117117
LongGauge longGauge = metricRegistry.addLongGauge(NAME, METRIC_OPTIONS);
118-
assertThat(longGauge.getDefaultTimeSeries()).isSameAs(longGauge.getDefaultTimeSeries());
118+
assertThat(longGauge.getDefaultTimeSeries()).isSameInstanceAs(longGauge.getDefaultTimeSeries());
119119
assertThat(longGauge.getDefaultTimeSeries())
120-
.isSameAs(longGauge.getOrCreateTimeSeries(LABEL_VALUES));
120+
.isSameInstanceAs(longGauge.getOrCreateTimeSeries(LABEL_VALUES));
121121

122122
DoubleGauge doubleGauge = metricRegistry.addDoubleGauge(NAME_2, METRIC_OPTIONS);
123-
assertThat(doubleGauge.getDefaultTimeSeries()).isSameAs(doubleGauge.getDefaultTimeSeries());
124123
assertThat(doubleGauge.getDefaultTimeSeries())
125-
.isSameAs(doubleGauge.getOrCreateTimeSeries(LABEL_VALUES));
124+
.isSameInstanceAs(doubleGauge.getDefaultTimeSeries());
125+
assertThat(doubleGauge.getDefaultTimeSeries())
126+
.isSameInstanceAs(doubleGauge.getOrCreateTimeSeries(LABEL_VALUES));
126127

127128
LongCumulative longCumulative = metricRegistry.addLongCumulative(NAME, METRIC_OPTIONS);
128129
assertThat(longCumulative.getDefaultTimeSeries())
129-
.isSameAs(longCumulative.getDefaultTimeSeries());
130+
.isSameInstanceAs(longCumulative.getDefaultTimeSeries());
130131
assertThat(longCumulative.getDefaultTimeSeries())
131-
.isSameAs(longCumulative.getOrCreateTimeSeries(LABEL_VALUES));
132+
.isSameInstanceAs(longCumulative.getOrCreateTimeSeries(LABEL_VALUES));
132133

133134
DoubleCumulative doubleCumulative = metricRegistry.addDoubleCumulative(NAME_2, METRIC_OPTIONS);
134135
assertThat(doubleCumulative.getDefaultTimeSeries())
135-
.isSameAs(doubleCumulative.getDefaultTimeSeries());
136+
.isSameInstanceAs(doubleCumulative.getDefaultTimeSeries());
136137
assertThat(doubleCumulative.getDefaultTimeSeries())
137-
.isSameAs(doubleCumulative.getOrCreateTimeSeries(LABEL_VALUES));
138+
.isSameInstanceAs(doubleCumulative.getOrCreateTimeSeries(LABEL_VALUES));
138139
}
139140

140141
@Test

api/src/test/java/io/opencensus/stats/NoopStatsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected Iterator<Tag> getIterator() {
5858
@Test
5959
public void noopStatsComponent() {
6060
assertThat(NoopStats.newNoopStatsComponent().getStatsRecorder())
61-
.isSameAs(NoopStats.getNoopStatsRecorder());
61+
.isSameInstanceAs(NoopStats.getNoopStatsRecorder());
6262
assertThat(NoopStats.newNoopStatsComponent().getViewManager())
6363
.isInstanceOf(NoopStats.newNoopViewManager().getClass());
6464
}

api/src/test/java/io/opencensus/tags/InternalUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ protected Iterator<Tag> getIterator() {
3939
return iterator;
4040
}
4141
};
42-
assertThat(InternalUtils.getTags(ctx)).isSameAs(iterator);
42+
assertThat(InternalUtils.getTags(ctx)).isSameInstanceAs(iterator);
4343
}
4444
}

api/src/test/java/io/opencensus/tags/NoopTagsTest.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ public String get(Object carrier, String key) {
6969

7070
@Test
7171
public void noopTagsComponent() {
72-
assertThat(NoopTags.newNoopTagsComponent().getTagger()).isSameAs(NoopTags.getNoopTagger());
72+
assertThat(NoopTags.newNoopTagsComponent().getTagger())
73+
.isSameInstanceAs(NoopTags.getNoopTagger());
7374
assertThat(NoopTags.newNoopTagsComponent().getTagPropagationComponent())
74-
.isSameAs(NoopTags.getNoopTagPropagationComponent());
75+
.isSameInstanceAs(NoopTags.getNoopTagPropagationComponent());
7576
}
7677

7778
@Test
@@ -107,12 +108,13 @@ public void preventSettingStateAfterGettingState_SameState() {
107108
@Test
108109
public void noopTagger() {
109110
Tagger noopTagger = NoopTags.getNoopTagger();
110-
assertThat(noopTagger.empty()).isSameAs(NoopTags.getNoopTagContext());
111-
assertThat(noopTagger.getCurrentTagContext()).isSameAs(NoopTags.getNoopTagContext());
112-
assertThat(noopTagger.emptyBuilder()).isSameAs(NoopTags.getNoopTagContextBuilder());
113-
assertThat(noopTagger.toBuilder(TAG_CONTEXT)).isSameAs(NoopTags.getNoopTagContextBuilder());
114-
assertThat(noopTagger.currentBuilder()).isSameAs(NoopTags.getNoopTagContextBuilder());
115-
assertThat(noopTagger.withTagContext(TAG_CONTEXT)).isSameAs(NoopScope.getInstance());
111+
assertThat(noopTagger.empty()).isSameInstanceAs(NoopTags.getNoopTagContext());
112+
assertThat(noopTagger.getCurrentTagContext()).isSameInstanceAs(NoopTags.getNoopTagContext());
113+
assertThat(noopTagger.emptyBuilder()).isSameInstanceAs(NoopTags.getNoopTagContextBuilder());
114+
assertThat(noopTagger.toBuilder(TAG_CONTEXT))
115+
.isSameInstanceAs(NoopTags.getNoopTagContextBuilder());
116+
assertThat(noopTagger.currentBuilder()).isSameInstanceAs(NoopTags.getNoopTagContextBuilder());
117+
assertThat(noopTagger.withTagContext(TAG_CONTEXT)).isSameInstanceAs(NoopScope.getInstance());
116118
}
117119

118120
@Test
@@ -131,12 +133,14 @@ public void noopTagger_WithTagContext_DisallowsNull() {
131133

132134
@Test
133135
public void noopTagContextBuilder() {
134-
assertThat(NoopTags.getNoopTagContextBuilder().build()).isSameAs(NoopTags.getNoopTagContext());
136+
assertThat(NoopTags.getNoopTagContextBuilder().build())
137+
.isSameInstanceAs(NoopTags.getNoopTagContext());
135138
assertThat(NoopTags.getNoopTagContextBuilder().put(KEY, VALUE).build())
136-
.isSameAs(NoopTags.getNoopTagContext());
137-
assertThat(NoopTags.getNoopTagContextBuilder().buildScoped()).isSameAs(NoopScope.getInstance());
139+
.isSameInstanceAs(NoopTags.getNoopTagContext());
140+
assertThat(NoopTags.getNoopTagContextBuilder().buildScoped())
141+
.isSameInstanceAs(NoopScope.getInstance());
138142
assertThat(NoopTags.getNoopTagContextBuilder().put(KEY, VALUE).buildScoped())
139-
.isSameAs(NoopScope.getInstance());
143+
.isSameInstanceAs(NoopScope.getInstance());
140144
}
141145

142146
@Test
@@ -175,9 +179,9 @@ public void noopTagContext() {
175179
@Test
176180
public void noopTagPropagationComponent() {
177181
assertThat(NoopTags.getNoopTagPropagationComponent().getBinarySerializer())
178-
.isSameAs(NoopTags.getNoopTagContextBinarySerializer());
182+
.isSameInstanceAs(NoopTags.getNoopTagContextBinarySerializer());
179183
assertThat(NoopTags.getNoopTagPropagationComponent().getCorrelationContextFormat())
180-
.isSameAs(NoopTags.getNoopTagContextTextSerializer());
184+
.isSameInstanceAs(NoopTags.getNoopTagContextTextSerializer());
181185
}
182186

183187
@Test

api/src/test/java/io/opencensus/trace/CurrentSpanUtilsTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void getCurrentSpan() {
7777
Context origContext = ContextUtils.withValue(Context.current(), span).attach();
7878
// Make sure context is detached even if test fails.
7979
try {
80-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
80+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
8181
} finally {
8282
Context.current().detach(origContext);
8383
}
@@ -89,7 +89,7 @@ public void withSpan_CloseDetaches() {
8989
assertThat(CurrentSpanUtils.getCurrentSpan()).isEqualTo(BlankSpan.INSTANCE);
9090
Scope ws = CurrentSpanUtils.withSpan(span, false);
9191
try {
92-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
92+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
9393
} finally {
9494
ws.close();
9595
}
@@ -102,7 +102,7 @@ public void withSpan_CloseDetachesAndEndsSpan() {
102102
assertThat(CurrentSpanUtils.getCurrentSpan()).isEqualTo(BlankSpan.INSTANCE);
103103
Scope ss = CurrentSpanUtils.withSpan(span, true);
104104
try {
105-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
105+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
106106
} finally {
107107
ss.close();
108108
}
@@ -118,7 +118,7 @@ public void withSpanRunnable() {
118118
@Override
119119
public void run() {
120120
// When we run the runnable we will have the span in the current Context.
121-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
121+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
122122
}
123123
};
124124
CurrentSpanUtils.withSpan(span, false, runnable).run();
@@ -134,7 +134,7 @@ public void withSpanRunnable_EndSpan() {
134134
@Override
135135
public void run() {
136136
// When we run the runnable we will have the span in the current Context.
137-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
137+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
138138
}
139139
};
140140
CurrentSpanUtils.withSpan(span, true, runnable).run();
@@ -151,7 +151,7 @@ public void withSpanRunnable_WithError() {
151151
@Override
152152
public void run() {
153153
// When we run the runnable we will have the span in the current Context.
154-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
154+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
155155
throw error;
156156
}
157157
};
@@ -170,7 +170,7 @@ public void withSpanRunnable_WithErrorNoMessage() {
170170
@Override
171171
public void run() {
172172
// When we run the runnable we will have the span in the current Context.
173-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
173+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
174174
throw error;
175175
}
176176
};
@@ -189,7 +189,7 @@ public void withSpanCallable() throws Exception {
189189
@Override
190190
public Object call() throws Exception {
191191
// When we run the runnable we will have the span in the current Context.
192-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
192+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
193193
return ret;
194194
}
195195
};
@@ -207,7 +207,7 @@ public void withSpanCallable_EndSpan() throws Exception {
207207
@Override
208208
public Object call() throws Exception {
209209
// When we run the runnable we will have the span in the current Context.
210-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
210+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
211211
return ret;
212212
}
213213
};
@@ -225,7 +225,7 @@ public void withSpanCallable_WithException() {
225225
@Override
226226
public Object call() throws Exception {
227227
// When we run the runnable we will have the span in the current Context.
228-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
228+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
229229
throw exception;
230230
}
231231
};
@@ -244,7 +244,7 @@ public void withSpanCallable_WithExceptionNoMessage() {
244244
@Override
245245
public Object call() throws Exception {
246246
// When we run the runnable we will have the span in the current Context.
247-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
247+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
248248
throw exception;
249249
}
250250
};
@@ -263,7 +263,7 @@ public void withSpanCallable_WithError() {
263263
@Override
264264
public Object call() throws Exception {
265265
// When we run the runnable we will have the span in the current Context.
266-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
266+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
267267
throw error;
268268
}
269269
};
@@ -282,7 +282,7 @@ public void withSpanCallable_WithErrorNoMessage() {
282282
@Override
283283
public Object call() throws Exception {
284284
// When we run the runnable we will have the span in the current Context.
285-
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameAs(span);
285+
assertThat(CurrentSpanUtils.getCurrentSpan()).isSameInstanceAs(span);
286286
throw error;
287287
}
288288
};

api/src/test/java/io/opencensus/trace/SpanBuilderTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,47 +49,47 @@ public void setUp() {
4949

5050
@Test
5151
public void startScopedSpan() {
52-
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
52+
assertThat(tracer.getCurrentSpan()).isSameInstanceAs(BlankSpan.INSTANCE);
5353
Scope scope = spanBuilder.startScopedSpan();
5454
try {
55-
assertThat(tracer.getCurrentSpan()).isSameAs(span);
55+
assertThat(tracer.getCurrentSpan()).isSameInstanceAs(span);
5656
} finally {
5757
scope.close();
5858
}
5959
verify(span).end(EndSpanOptions.DEFAULT);
60-
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
60+
assertThat(tracer.getCurrentSpan()).isSameInstanceAs(BlankSpan.INSTANCE);
6161
}
6262

6363
@Test
6464
public void startSpanAndRun() {
65-
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
65+
assertThat(tracer.getCurrentSpan()).isSameInstanceAs(BlankSpan.INSTANCE);
6666
spanBuilder.startSpanAndRun(
6767
new Runnable() {
6868
@Override
6969
public void run() {
70-
assertThat(tracer.getCurrentSpan()).isSameAs(span);
70+
assertThat(tracer.getCurrentSpan()).isSameInstanceAs(span);
7171
}
7272
});
7373
verify(span).end(EndSpanOptions.DEFAULT);
74-
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
74+
assertThat(tracer.getCurrentSpan()).isSameInstanceAs(BlankSpan.INSTANCE);
7575
}
7676

7777
@Test
7878
public void startSpanAndCall() throws Exception {
7979
final Object ret = new Object();
80-
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
80+
assertThat(tracer.getCurrentSpan()).isSameInstanceAs(BlankSpan.INSTANCE);
8181
assertThat(
8282
spanBuilder.startSpanAndCall(
8383
new Callable<Object>() {
8484
@Override
8585
public Object call() throws Exception {
86-
assertThat(tracer.getCurrentSpan()).isSameAs(span);
86+
assertThat(tracer.getCurrentSpan()).isSameInstanceAs(span);
8787
return ret;
8888
}
8989
}))
9090
.isEqualTo(ret);
9191
verify(span).end(EndSpanOptions.DEFAULT);
92-
assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
92+
assertThat(tracer.getCurrentSpan()).isSameInstanceAs(BlankSpan.INSTANCE);
9393
}
9494

9595
@Test
@@ -99,6 +99,6 @@ public void doNotCrash_NoopImplementation() throws Exception {
9999
spanBuilder.setRecordEvents(true);
100100
spanBuilder.setSampler(Samplers.alwaysSample());
101101
spanBuilder.setSpanKind(Kind.SERVER);
102-
assertThat(spanBuilder.startSpan()).isSameAs(BlankSpan.INSTANCE);
102+
assertThat(spanBuilder.startSpan()).isSameInstanceAs(BlankSpan.INSTANCE);
103103
}
104104
}

0 commit comments

Comments
 (0)