I'm trying to mock ContainerRequestContext using Mockito, but i got the follow error:
java.lang.ClassFormatError: Absent Code attribute in method
that is not native or abstract in class file
javax/ws/rs/core/Response
My goal is set headers inside context to test an interceptor class.
@RunWith(MockitoJUnitRunner.class) public class
MyInterceptorTest
@Mock
ContainerRequestContext context;
@Mock
MyService service;
@InjectMocks
MyInterceptor interceptor;
@Test
public void shouldAuthorizeUsingHEader() {
when(context.getHeaderString("header1")).thenReturn("123456");
when(context.getHeaderString("header2")).thenReturn("BigBall");
interceptor.filter(context);
verify(context, never()).abortWith(any(Response.class));
}