8000 Refactor tests · DataDog/dd-trace-java@f617c28 · GitHub
[go: up one dir, main page]

Skip to content

Commit f617c28

Browse files
committed
Refactor tests
1 parent 216bac7 commit f617c28

File tree

4 files changed

+40
-36
lines changed

4 files changed

+40
-36
lines changed

dd-java-agent/instrumentation/java-lang/src/test/groovy/datadog/trace/instrumentation/java/lang/StringBuilderCallSiteTest.groovy

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -174,77 +174,60 @@ class StringBuilderCallSiteTest extends AgentTestRunner {
174174
ex.stackTrace.find { it.className == StringBuilderCallSite.name } == null
175175
}
176176
177-
def 'test string builder substring call site'() {
177+
def 'test string #type substring call site'() {
178178
setup:
179179
final iastModule = Mock(StringModule)
180180
InstrumentationBridge.registerIastModule(iastModule)
181181
182182
when:
183-
final result = TestStringBuilderSuite.substring(param, beginIndex)
183+
final result = suite.substring(param, beginIndex)
184184
185185
then:
186186
result == expected
187187
1 * iastModule.onStringSubSequence(param, beginIndex, param.length(), expected)
188188
0 * _
189189
190190
where:
191-
param | beginIndex | expected
192-
sb('012345') | 1 | '12345'
191+
type | suite | param | beginIndex | expected
192+
"builder" | new TestStringBuilderSuite() | sb('012345') | 1 | '12345'
193+
"buffer" | new TestStringBufferSuite() | sbf('012345') | 1 | '12345'
193194
}
194195
195-
def 'test string buffer substring call site'() {
196+
def 'test string #type substring with endIndex call site'() {
196197
setup:
197198
final iastModule = Mock(StringModule)
198199
InstrumentationBridge.registerIastModule(iastModule)
199200
200201
when:
201-
final result = TestStringBufferSuite.substring(param, beginIndex)
202-
203-
then:
204-
result == expected
205-
1 * iastModule.onStringSubSequence(param, beginIndex, param.length(), expected)
206-
0 * _
207-
208-
where:
209-
param | beginIndex | expected
210-
sbf('012345') | 1 | '12345'
211-
}
212-
213-
def 'test string builder/buffer #method with endIndex call site'() {
214-
setup:
215-
final iastModule = Mock(StringModule)
216-
InstrumentationBridge.registerIastModule(iastModule)
217-
218-
when:
219-
final result = suite."$method"(param, beginIndex, endIndex)
202+
final result = suite.substring(param, beginIndex, endIndex)
220203
221204
then:
222205
result == expected
223206
1 * iastModule.onStringSubSequence(param, beginIndex, endIndex, expected)
224207
0 * _
225208
226209
where:
227-
suite | method | param | beginIndex | endIndex | expected
228-
new TestStringBuilderSuite() | "substring" | sb('012345') | 1 | 5 | '1234'
229-
new TestStringBufferSuite() | "substring" | sbf('012345') | 1 | 5 | '1234'
210+
type | suite | param | beginIndex | endIndex | expected
211+
"builder" | new TestStringBuilderSuite() | sb('012345') | 1 | 5 | '1234'
212+
"buffer" | new TestStringBufferSuite() | sbf('012345') | 1 | 5 | '1234'
230213
}
231214
232-
def 'test string builder/buffer #method with endIndex call site'() {
215+
def 'test string #type subSequence with endIndex call site'() {
233216
setup:
234217
final iastModule = Mock(StringModule)
235218
InstrumentationBridge.registerIastModule(iastModule)
236219
237220
when:
238-
final result = suite."$method"(param, beginIndex, endIndex)
221+
final result = suite.subSequence(param, beginIndex, endIndex)
239222
240223
then:
241224
result == expected
242225
1 * iastModule.onStringSubSequence(param, beginIndex, endIndex, expected)
243226
0 * _
244227
245228
where:
246-
suite | method | param | beginIndex | endIndex | expected
247-
new TestStringBuilderSuite() | "subSequence" | sb('012345') | 1 | 5 | '1234'
229+
type | suite | param | beginIndex | endIndex | expected
230+
"builder" | new TestStringBuilderSuite() | sb('012345') | 1 | 5 | '1234'
248231
}
249232
250233
private static class BrokenToString {

dd-java-agent/instrumentation/java-lang/src/test/java/foo/bar/TestAbstractStringBuilderSuite.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@ public interface TestAbstractStringBuilderSuite<E> {
1212

1313
void append(final E target, final Object param);
1414

15+
String substring(final E self, final int beginIndex, final int endIndex);
16+
17+
String substring(final E self, final int beginIndex);
18+
19+
CharSequence subSequence(final E self, final int beginIndex, final int endIndex);
20+
1521
String toString(final E target);
1622
}

dd-java-agent/instrumentation/java-lang/src/test/java/foo/bar/TestStringBufferSuite.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,28 @@ public String toString(final StringBuffer buffer) {
5252
return result;
5353
}
5454

55-
public static String substring(StringBuffer self, int beginIndex, int endIndex) {
55+
@Override
56+
public String substring(final StringBuffer self, final int beginIndex, final int endIndex) {
5657
LOGGER.debug("Before string buffer substring {} from {} to {}", self, beginIndex, endIndex);
5758
final String result = self.substring(beginIndex, endIndex);
5859
LOGGER.debug("After string buffer substring {}", result);
5960
return result;
6061
}
6162

62-
public static String substring(StringBuffer self, int beginIndex) {
63+
@Override
64+
public String substring(final StringBuffer self, final int beginIndex) {
6365
LOGGER.debug("Before string buffer substring {} from {}", self, beginIndex);
6466
final String result = self.substring(beginIndex);
6567
LOGGER.debug("After string buffer substring {}", result);
6668
return result;
6769
}
70+
71+
@Override
72+
public CharSequence subSequence(
73+
final StringBuffer self, final int beginIndex, final int endIndex) {
74+
LOGGER.debug("Before string builder subSequence {} from {} to {}", self, beginIndex, endIndex);
75+
final CharSequence result = self.subSequence(beginIndex, endIndex);
76+
LOGGER.debug("After string builder subSequence {}", result);
77+
return result;
78+
}
6879
}

dd-java-agent/instrumentation/java-lang/src/test/java/foo/bar/TestStringBuilderSuite.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,25 @@ public String plus(final Object... items) {
7777
return result;
7878
}
7979

80-
public static String substring(StringBuilder self, int beginIndex, int endIndex) {
80+
@Override
81+
public String substring(final StringBuilder self, final int beginIndex, final int endIndex) {
8182
LOGGER.debug("Before string builder substring {} from {} to {}", self, beginIndex, endIndex);
8283
final String result = self.substring(beginIndex, endIndex);
8384
LOGGER.debug("After string builder substring {}", result);
8485
return result;
8586
}
8687

87-
public static String substring(StringBuilder self, int beginIndex) {
88+
@Override
89+
public String substring(final StringBuilder self, final int beginIndex) {
8890
LOGGER.debug("Before string builder substring {} from {}", self, beginIndex);
8991
final String result = self.substring(beginIndex);
9092
LOGGER.debug("After string builder substring {}", result);
9193
return result;
9294
}
9395

94-
public static CharSequence subSequence(StringBuilder self, int beginIndex, int endIndex) {
96+
@Override
97+
public CharSequence subSequence(
98+
final StringBuilder self, final int beginIndex, final int endIndex) {
9599
LOGGER.debug("Before string builder subSequence {} from {} to {}", self, beginIndex, endIndex);
96100
final CharSequence result = self.subSequence(beginIndex, endIndex);
97101
LOGGER.debug("After string builder subSequence {}", result);

0 commit comments

Comments
 (0)
0