Mockito matcher and array of primitives

后端 未结 8 1337
既然无缘
既然无缘 2021-01-30 05:53

With Mockito, I want to verify() a method call with byte[] in its argument list, but I didn\'t find how to write this.

 myMethod( byte[         


        
8条回答
  •  不要未来只要你来
    2021-01-30 06:30

    You can always create a custom Matcher using argThat

    Mockito.verify(yourMockHere).methodCallToBeVerifiedOnYourMockHere(ArgumentMatchers.argThat(new ArgumentMatcher() {
        @Override
        public boolean matches(Object argument) {
            YourTypeHere[] yourArray = (YourTypeHere[]) argument;
            // Do whatever you like, here is an example:
            if (!yourArray[0].getStringValue().equals("first_arr_val")) {
                return false;
            }
            return true;
        }
    }));
    
        

    提交回复
    热议问题