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

[Bug]: Object Mocking failed when there is a private field type different #43156

Closed
daneshk opened this issue Jul 23, 2024 · 3 comments · Fixed by #43221
Closed

[Bug]: Object Mocking failed when there is a private field type different #43156

daneshk opened this issue Jul 23, 2024 · 3 comments · Fixed by #43221
Assignees
Labels
Area/TestFramework Priority/High Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug
Milestone

Comments

@daneshk
Copy link
Member

daneshk commented Jul 23, 2024

Description

When we have private fields in the Mock object which is not correctly mapped with the field types of the original object, mocking fails giving the following error,

error: incompatible field type 'int' provided for field name
        at ballerina.test.0:mock(mock.bal:309)
           danesh.object_mocking$test.0.tests.init-tests:getMockClient(tests/init-tests.bal:5)

Do we need to validate private fields when we do object mocking?

Steps to Reproduce

You can reproduce the issue with the following source code

Source code

import ballerina/io;

Foo f = initialize();

public function initialize() returns Foo {
    return new Foo();
}

public class Foo {

    private string name;
    public function foo() {
        io:println("Hello, Foo!");
    }
    
}

public class Bar {

    private int name;
    public function foo() {
        io:println("Hello, Bar!");
    }

}

public function main() {
    io:println("Hello, World!");
}

Test code

import ballerina/test;

@test:Mock {functionName: "initialize"}
isolated function getMockClient() returns Foo {
    return test:mock(Foo, new Bar());
}

Affected Version(s)

Latest Ballerina versions

OS, DB, other environment details and versions

No response

Related area

--> Testerina

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Jul 23, 2024
@daneshk daneshk added Area/TestFramework Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) and removed userCategory/Compilation needTriage The issue has to be inspected and labeled manually labels Jul 23, 2024
@daneshk daneshk added this to the 2201.10.0 milestone Jul 23, 2024
@daneshk
Copy link
Member Author

daneshk commented Jul 23, 2024

Can we get this fixed with update 10 please, as it is blocking the feature ballerina-platform/ballerina-library#5840

@Dilhasha
Copy link
Contributor

Can we get this fixed with update 10 please, as it is blocking the feature ballerina-platform/ballerina-library#5840

Ack.

Copy link

github-actions bot commented Aug 2, 2024

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@Dilhasha Dilhasha added the Reason/EngineeringMistake The issue occurred due to a mistake made in the past. label Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/TestFramework Priority/High Reason/EngineeringMistake The issue occurred due to a mistake made in the past. Team/DevTools Ballerina Developer Tooling ( CLI, Test FW, Package Management, OpenAPI, APIDocs ) Type/Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants