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

getArgumentAt is removed in 2.7.6 #945

Closed
mkolesnikov opened this issue Feb 14, 2017 · 12 comments
Closed

getArgumentAt is removed in 2.7.6 #945

mkolesnikov opened this issue Feb 14, 2017 · 12 comments
Labels

Comments

@mkolesnikov
Copy link

I could not find this method in 2.7.6 version of InvocationOnMock and there is also no information in the release notes in the incompatible-changes. Are you going to add it again or what was the reason to remove?

@TimvdLippe
Copy link
Contributor

It seems that the deprecated method was incorrectly removed in #404. We have 2 options here: Re-introduce or document as breaking change. Personally I think we should list this as breaking change, which is unfortunate that we didn't list it earlier.

Also as an action point, I propose to always list a "deprecated since" mention to prevent these incorrect removal of deprecated features.

@ChristianSchwarz
Copy link
Contributor

T getArgumentAt(int index, Class<T> type) was deprecated with the introduction of T getArgument(int index) in v2.0.51-beta with PR #373. So yes this is a breaking change, the PR and the corresponding issue #365 should be labeled with [incompatible 1.*].

@ChristianSchwarz
Copy link
Contributor

ChristianSchwarz commented Feb 16, 2017

I changed the "What's-new-in-Mockito-2" wiki page as suggested see -> c7c9b9c .

@bric3
Copy link
Contributor

bric3 commented Feb 17, 2017

@ChristianSchwarz Thanks ! We missed that change.

I labelled the 3 tickets as 1.x incompatible.

@Yogyatha9
Copy link

Has this method been removed in 3.2.0 again ? I've just uplifted to 3.2.0 recently from 1.7.x and the usage of this method is again a compilation error !

@TimvdLippe
Copy link
Contributor

No this method has not been removed. Are you sure you are compiling with the correct version of Mockito?

@Yogyatha9
Copy link

Hi... thanks for the spontaneous reply. Yes I'm using mockito-core 3.2.0 and since then the getArgumentAt method usage results in a compilation error ! I've checked my pom and 3.2.0 is the only mockito version being referred to. Is there anything that I'm missing if its not dropped/deprecated?

@TimvdLippe
Copy link
Contributor

Please create a new issue with a reproduction case that we can debug.

@Yogyatha9
Copy link

Yep raised :: #1837. Thanks

alexwlchan added a commit to wellcomecollection/scala-libs that referenced this issue Nov 24, 2020
StefRe added a commit to StefRe/opacclient that referenced this issue May 25, 2021
After update of Mockito from 1.10.19 to 3.8.0 (see 11833f3)
testLoadPages did no longer compile as getArgumentAt was removed in Mockito 2.7.6 (see
mockito/mockito#945). Fixed by replacing with getArgument.
@mirabilos
Copy link

@ChristianSchwarz the documentation change you did breaks for me though.

    when(metadata.getColumnLabel(anyInt())).thenAnswer(new Answer<String>() {
        @Override
        public String answer(final InvocationOnMock invocation) throws Throwable {
            final int col = invocation.getArgument(0) - 1;
            return labels[col];
        }
    });

This reports an error because Object and int cannot be subtracted. The old form worked:

        final int col = invocation.getArgumentAt(0, Integer.class) - 1;

@ChristianSchwarz
Copy link
Contributor

ChristianSchwarz commented Apr 19, 2022

@mirabilos Haven't worked with Java for a long time now. You could try invocation.getArgument<int>(..) or invocation.getArgument<Integer>(..) then compiler can unbox Integer to int. Hope that helps.
Otherwise cast to Integer

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

No branches or pull requests

6 participants