Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EasyMock Long null match in method parameter

I want to match a method which has 3 paramters: A String, A Long and A customObject

The test should match the String exactly, ensure that the Long is null and ensure that the custom object passed is of the correct type.

Something like:

    EasyMock.expect(mockClass.myMethod(
                        EasyMock.eq("exact string"), 
                        EasyMock.isA(Long.class), 
                        EasyMock.isA(CustomObject.class)));

This is not matching the method correctly probably because of the Long which is supposed to be null.

I cannot put EasyMock.isNull() since it will be a specific matching and generics and specifics can't go together. Any tips ?

like image 842
Garfield Avatar asked May 21 '26 17:05

Garfield


1 Answers

I don't understand why you couldn't use isNull().

EasyMock.expect(mockClass.myMethod(
                    EasyMock.eq("exact string"), 
                    EasyMock.isNull(Long.class), 
                    EasyMock.isA(CustomObject.class)));

should be fine. Or

EasyMock.expect(mockClass.myMethod(
                    EasyMock.eq("exact string"), 
                    EasyMock.<Long>isNull(), 
                    EasyMock.isA(CustomObject.class)));

which should be fine as well.

What you can't have is

EasyMock.expect(mockClass.myMethod(
                    EasyMock.eq("exact string"), 
                    null, 
                    EasyMock.isA(CustomObject.class)));
like image 69
JB Nizet Avatar answered May 24 '26 05:05

JB Nizet