Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Fix legacy mocking failure #41686

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,26 @@
// Get the Mock Function map from the pkgNode
Map<String, String> mockFunctionMap = pkgNode.getTestablePkg().getMockFunctionNamesMap();

// Get the set of functions to generate
// Get all the imports symbols from the testable package
Set<String> mockFunctionSet = mockFunctionMap.keySet();
ArrayList<String> importsList = new ArrayList<>();
for (BLangImportPackage importPkg : pkgNode.getTestablePkg().getImports()) {
if (importPkg.symbol == null) {
continue;

Check warning on line 123 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java#L123

Added line #L123 was not covered by tests
}
if (!importPkg.symbol.toString().contains(testPackageSymbol)) {
importsList.add(importPkg.symbol.toString());

Check warning on line 126 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java#L126

Added line #L126 was not covered by tests
}
}

// Get all the imports from the current package
for (BLangImportPackage importPkg : pkgNode.getImports()) {
if (importPkg.symbol == null) {
continue;

Check warning on line 133 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java#L133

Added line #L133 was not covered by tests
}
if (importsList.contains(importPkg.symbol.toString())) {
continue;

Check warning on line 136 in compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java

View check run for this annotation

Codecov / codecov/patch

compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/MockDesugar.java#L136

Added line #L136 was not covered by tests
}
if (!importPkg.symbol.toString().contains(testPackageSymbol)) {
importsList.add(importPkg.symbol.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Running Tests with Coverage

function_mocking_legacy
[pass] testIntAdd
[pass] testIntMul


1 passing
2 passing
0 failing
0 skipped

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Running Tests with Coverage

function_mocking_legacy
[pass] testIntAdd
[pass] testIntMul


1 passing
2 passing
0 failing
0 skipped

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
import function_mocking_legacy.moduleB;

function intAdd(int a, int b) returns int {
return a + b;
}

public function intMul3Num(int a, int b, int c) returns int {
int result = moduleB:intMul(a, b);
return moduleB:intMul(result, c);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2023 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 Inc. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

public function intMul(int a, int b) returns int {
return a * b;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,21 @@ function intSubMock(int a, int b) returns int {
return 0;
}

@test:Mock {
moduleName: "function_mocking_legacy.moduleB",
functionName: "intMul"
}
function intMulMock(int a, int b) returns int {
return 1;
}

@test:Config {}
function testIntAdd() {
test:assertEquals(intAdd(3, 7), 5);
test:assertEquals(moduleA:intSub(3, 7), 0);
}

@test:Config {}
function testIntMul() {
test:assertEquals(intMul3Num(3, 7, 2), 1);
}
Loading