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

SetParams should implement equals and hashcode #2687

Closed
JeffAtDeere opened this issue Nov 11, 2021 · 2 comments · Fixed by #3728
Closed

SetParams should implement equals and hashcode #2687

JeffAtDeere opened this issue Nov 11, 2021 · 2 comments · Fixed by #3728

Comments

@JeffAtDeere
Copy link

JeffAtDeere commented Nov 11, 2021

Expected behavior

SetParams should implement equals and hashcode. Without those, verifying mock interactions is harder. For example,

    @Test
    void test() {
        Jedis jedis = Mockito.mock(Jedis.class);
        jedis.set("key", "value", new SetParams().ex(3600L));
        Mockito.verify(jedis).set("key", "value", new SetParams().ex(3600L));
    }

fails with

Argument(s) are different! Wanted:
jedis.set("key", "value", [ex, 3600]);
-> at x.test(x.java:89)
Actual invocations have different arguments:
jedis.set("key", "value", [ex, 3600]);
-> at x.test(x.java:88)

because of a lack of equals and hashcode on SetParams.

To write a passing test, one has to:

    @Test
    void test() {
        Jedis jedis = Mockito.mock(Jedis.class);
        jedis.set("key", "value", new SetParams().ex(3600L));
        Mockito.verify(jedis).set(eq("key"), eq("value"), argThat((SetParams p) -> p.getParam("ex").equals(3600L)));
    }

and know that the internal structure of SetParams is a map, that the private key is "ex", and that getParam's returned <T> is actually a Long.

Jedis version:

3.7.0

Redis version:

N/A

Java version:

11

Mockito version:

3.3.3

Copy link

github-actions bot commented Jan 3, 2024

This issue is marked stale. It will be closed in 30 days if it is not updated.

@Lcarrot
Copy link
Contributor

Lcarrot commented Feb 19, 2024

Hello, can i try to solve this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants