Skip to content

Commit

Permalink
refactor - Remove the logic of eliminating spaces in param list (#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Jun 27, 2024
1 parent 37cce5c commit f343d89
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
1 change: 0 additions & 1 deletion extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
// Licensed under the MIT license.

export { activate, deactivate } from './src/extension';
export * from './src/utils/commandUtils';
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public static String parseFullName(IJavaElement element, TestLevel level, TestKi
// them out now.
final String methodName = JavaElementLabelsCore.getElementLabel(element,
JavaElementLabelsCore.ALL_DEFAULT)
.replaceAll("<.*?>", "")
.replaceAll(" ", "");
.replaceAll("<.*?>", "");
return className + "#" + methodName;
} else {
return method.getDeclaringType().getFullyQualifiedName() + "#" + method.getElementName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ private String createTestName(ITestResult result) {

for (final Class<?> paramClazz : result.getMethod().getConstructorOrMethod().getMethod().getParameterTypes()) {
params.append(paramClazz.getSimpleName().replaceAll("<.*?>", ""));
params.append(",");
params.append(", ");
}

// Remove the last ", "
if (params.length() > 0) {
params.delete(params.length() - 1, params.length());
params.delete(params.length() - 2, params.length());
}

return className + "#" + methodName + "(" + params.toString() + ")";
Expand Down
12 changes: 5 additions & 7 deletions src/runners/junitRunner/JUnitRunnerResultAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,12 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
className = `${className}$${nestedClassName}`;
} else if (part.startsWith(JUnitTestPart.TEST_TEMPLATE)) {
const rawMethodName: string = part.substring(JUnitTestPart.TEST_TEMPLATE.length)
.replace(/\\,/g, ',')
.replace(/ /g, '');
.replace(/\\,/g, ',');
// If the method name exists then we want to include the '#' qualifier.
methodName = `#${this.getJUnit5MethodName(rawMethodName)}`;
} else if (part.startsWith(JUnitTestPart.PROPERTY)) {
const rawMethodName: string = part.substring(JUnitTestPart.PROPERTY.length)
.replace(/\\,/g, ',')
.replace(/ /g, '');
.replace(/\\,/g, ',');
// If the method name exists then we want to include the '#' qualifier.
methodName = `#${this.getJUnit5MethodName(rawMethodName)}`;
} else if (part.startsWith(JUnitTestPart.TEST_TEMPLATE_INVOCATION)) {
Expand Down Expand Up @@ -285,11 +283,11 @@ export class JUnitRunnerResultAnalyzer extends RunnerResultAnalyzer {
const params: string[] = rawParamsString.split(',');
let paramString: string = '';
params.forEach((param: string) => {
paramString += `${param.substring(param.lastIndexOf('.') + 1)},`;
paramString += `${param.substring(param.lastIndexOf('.') + 1)}, `;
});
// We want to remove the final comma.
// We want to remove the final comma and space.
if (paramString.length > 0) {
paramString = paramString.substring(0, paramString.length - 1);
paramString = paramString.substring(0, paramString.length - 2);
}

const methodName: string = rawName.substring(0, rawName.indexOf('('));
Expand Down
4 changes: 2 additions & 2 deletions test/suite/JUnitAnalyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ org.opentest4j.AssertionFailedError: expected: <1> but was: <2>
});

test("can handle test cases with more than 3 arguments", () => {
const testItem = generateTestItem(testController, '[email protected]#testMultiArguments(String,String,String)', TestKind.JUnit5, new Range(10, 0, 16, 0));
const testItem = generateTestItem(testController, '[email protected]#testMultiArguments(String, String, String)', TestKind.JUnit5, new Range(10, 0, 16, 0));
const testRunRequest = new TestRunRequest([testItem], []);
const testRun = testController.createTestRun(testRunRequest);
const startedSpy = sinon.spy(testRun, 'started');
Expand Down Expand Up @@ -439,7 +439,7 @@ org.opentest4j.AssertionFailedError: expected: <1> but was: <2>
});

test("can handle normal test method with multiple arguments", () => {
const testItem = generateTestItem(testController, '[email protected]#test(Vertx,VertxTestContext)', TestKind.JUnit5, new Range(10, 0, 16, 0));
const testItem = generateTestItem(testController, '[email protected]#test(Vertx, VertxTestContext)', TestKind.JUnit5, new Range(10, 0, 16, 0));
const testRunRequest = new TestRunRequest([testItem], []);
const testRun = testController.createTestRun(testRunRequest);
const startedSpy = sinon.spy(testRun, 'started');
Expand Down

0 comments on commit f343d89

Please sign in to comment.