mock BeanUtils.setProperty to throw an exception

Viewed 428

I have class A with a public foo function, that using a private boo function that uses BeanUtils.setProperty.

I want to test the scenario when setProperty will throw an exception (IllegalAccessException, InvocationTargetException, it doesn't matter).

I did a @Mock on BeanUtils, @InjectMocks on class A, and tried the following:

doThrow(new IllegalAccessException()).when(beanUtils).getProperty(any(),any(),any());

But I get the warning:

Static member 'org.apache.commons.beanutils.BeanUtils.getProperty(java.lang.Object, java.lang.String)' accessed via instance reference" and the exception "java.lang.IllegalArgumentException: No bean specified" when running.

0 Answers
Related