GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [PR open] Add feature to verify static methods calls in order · Issue #2548 · mockito/mockito

[PR open] Add feature to verify static methods calls in order #2548

New issue
Copy link
New issue
Copy link
Closed
#2549
Closed
[PR open] Add feature to verify static methods calls in order#2548
#2549
Copy link

Description

@mirkoalicastro
mirkoalicastro
opened on Jan 24, 2022
Issue body actions

TL;DR Mockito doesn't allow verifying static methods calls in order. I have implemented this feature here: #2549. If possible, I'd like to contribute; or discuss other ways to achieve the same.


Hey Mockito team.

This discussion relates to: https://groups.google.com/g/mockito/c/wjd9jIj_oBs. Since I'm not sure that the Google group is active, I'm posting it here for now.

This issue is about verifying static methods calls in order. I'm aware of the InOrder class, but we can't pass a MockedStatic instance. I had a closer look, and we can pass to it a Class instance. But the InOrder interface is not powerful enough to verify that a static method has been called:

public interface InOrder {
  <T> T verify(T mock);
  <T> T verify(T mock, VerificationMode mode);
  void verifyNoMoreInteractions();
}

To verify static calls, using method references and lambdas, we likely need two more methods in the InOrder interface, with signatures similar to MockedStatic#verify:

public interface MockedStatic<T> extends ScopedMock {
  void verify(Verification verification)
  void verify(Verification verification, VerificationMode mode);
  ...
}

What do you think of the InOrder interface exposing two methods to deal with the MockedStatic objects that accept both the MockedStatic and the Verification instances to use? Like the following:

void verify(MockedStatic<?> mockedStatic, MockedStatic.Verification verification);
void verify(MockedStatic<?> mockedStatic, MockedStatic.Verification verification, VerificationMode mode);

I made the above changes, and we can verify static methods, together with instance methods too. I have updated the tests as well in my PR.

Let me know if you are aware of other ways to achieve the same. If it is not doable, then please share your thoughts about the above, and if I can contribute in case.

Reacted by Roberto Cella and ododa

Activity

  1. mirkoalicastro
    added a commit that references this issue on Jan 24, 2022

    Fixes mockito#2548 : Makes InOrder able to verify static methods

    This issue will close once commit f15b566 is merged into the 'main' branch.
    f15b566
  2. rob93c commented on Feb 1, 2022

    @rob93c
    rob93c
    on Feb 1, 2022
    More actions

    As a Mockito user I would love to have this new feature @mirkoalicastro

  3. mirkoalicastro
    changed the title [-]Add feature to verify static methods calls in order[/-] [+][PR open] Add feature to verify static methods calls in order[/+] on Feb 1, 2022
  4. mirkoalicastro commented on Feb 1, 2022

    @mirkoalicastro
    mirkoalicastro
    on Feb 1, 2022
    ContributorAuthor
    More actions

    As a Mockito user I would love to have this new feature @mirkoalicastro

    I made it more clear that there is already a possible implementation with the mentioned PR, which includes tests as well, of course. I hope someone will look into this.

  5. mirkoalicastro commented on Feb 12, 2022

    @mirkoalicastro
    mirkoalicastro
    on Feb 12, 2022
    ContributorAuthor
    More actions

    @TimvdLippe Are you able to provide some feedback on this / to involve relevant people? Many thanks.

  6. TimvdLippe commented on Feb 15, 2022

    @TimvdLippe
    TimvdLippe
    on Feb 15, 2022
    Contributor
    More actions

    Sorry I hadn't gotten to it. I responded to the PR, it's looking good! We mainly need to figure out how we are handling the Class that is matching the mockedStatic, but I think in that case we should be passing that into the inOrder() method call. Let's iterate on the PR and see where it goes!

    Reacted by Mirko Alicastro
  7. TimvdLippe
    closed this as completedin #2549on Feb 16, 2022
  8. TimvdLippe
    added a commit that references this issue on Feb 16, 2022

    Fixes #2548: make InOrder able to verify static methods (#2549)

    This issue will close once commit 02d6356 is merged into the 'main' branch.
    02d6356
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.