1

How to check that compareTo method will be invoked with this argument new ComparableVersion("1"))

  verify(comparableVersion).compareTo(any(ComparableVersion.class));

Now I use any - this is not enough.

1 Answer 1

1

If you implement a proper equals method in your class, you can use the eq matcher. It will not verify your constructor, but it will verify against an object that has been initialized to a known state.

Sign up to request clarification or add additional context in comments.

2 Comments

If you have a proper equals method in your class, you don't need the eq matcher at all. Just pass the value that you want to compare it to directly, for example verify(comparableVersion).compareTo(new ComparableVersion("1")); - this will use your equals to compare the actual value to new ComparableVersions("1").
That's true, @DavidWallace. eq is actually not needed in this case at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.