JClassType bothAnnotationType = mock(JClassType.class);
when(bothAnnotationType.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
when(bothAnnotationType.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(true);
// Declare some standard methods
JMethod protectedMethod = mock(JMethod.class);
when(protectedMethod.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
when(protectedMethod.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(false);
JMethod notProtectedMethod = mock(JMethod.class);
when(notProtectedMethod.isAnnotationPresent(XsrfProtect.class)).thenReturn(false);
when(notProtectedMethod.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(true);
JMethod noAnnotationMethod = mock(JMethod.class);
when(noAnnotationMethod.isAnnotationPresent(XsrfProtect.class)).thenReturn(false);
when(noAnnotationMethod.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(false);
JMethod bothAnnotationMethod = mock(JMethod.class);
when(bothAnnotationMethod.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
when(bothAnnotationMethod.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(true);
// Test a protected method
when(protectedMethod.getEnclosingType()).thenReturn(protectedType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(protectedMethod));
when(protectedMethod.getEnclosingType()).thenReturn(notProtectedType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(protectedMethod));
when(protectedMethod.getEnclosingType()).thenReturn(noAnnotationType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(protectedMethod));
when(protectedMethod.getEnclosingType()).thenReturn(bothAnnotationType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(protectedMethod));
// Test a method that is explicitly not protected
when(notProtectedMethod.getEnclosingType()).thenReturn(protectedType);
assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(notProtectedMethod));
when(notProtectedMethod.getEnclosingType()).thenReturn(notProtectedType);
assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(notProtectedMethod));
when(notProtectedMethod.getEnclosingType()).thenReturn(noAnnotationType);
assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(notProtectedMethod));
when(notProtectedMethod.getEnclosingType()).thenReturn(bothAnnotationType);
assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(notProtectedMethod));
// Test a method that is explicitly not annotated at all
when(noAnnotationMethod.getEnclosingType()).thenReturn(protectedType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(noAnnotationMethod));
when(noAnnotationMethod.getEnclosingType()).thenReturn(notProtectedType);
assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(noAnnotationMethod));
when(noAnnotationMethod.getEnclosingType()).thenReturn(noAnnotationType);
assertFalse(XsrfRpcProxyCreator.isMethodXsrfProtected(noAnnotationMethod));
when(noAnnotationMethod.getEnclosingType()).thenReturn(bothAnnotationType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(noAnnotationMethod));
// Test a method that is annotated with both annotations
when(bothAnnotationMethod.getEnclosingType()).thenReturn(protectedType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(bothAnnotationMethod));
when(bothAnnotationMethod.getEnclosingType()).thenReturn(notProtectedType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(bothAnnotationMethod));
when(bothAnnotationMethod.getEnclosingType()).thenReturn(noAnnotationType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(bothAnnotationMethod));
when(bothAnnotationMethod.getEnclosingType()).thenReturn(bothAnnotationType);
assertTrue(XsrfRpcProxyCreator.isMethodXsrfProtected(bothAnnotationMethod));
}