GrantEvaluatorComposer implements AclComposer<GrantEvaluator> { @Override public GrantEvaluator and(GrantEvaluator lhs, GrantEvaluator rhs) { return new CompoundGrantEvaluator(lhs, rhs, GrantEvaluatorOperator.AND); }  @Override GrantEvaluator and(GrantEvaluator lhs, GrantEvaluator rhs); @Override GrantEvaluator or(GrantEvaluator lhs, GrantEvaluator rhs);  }
@Test public void should_rhs_not_be_evaluated_when_AND_operator_and_lhs_is_false___strong_ref() { when(lhs.isGranted(any(), any(), any())).thenReturn(false); GrantEvaluator grantEvaluator = composer.and(lhs, rhs); boolean granted = grantEvaluator.isGranted(null, null, "fake"); verify(lhs).isGranted(any(), any(), any()); verifyZeroInteractions(rhs); assertThat(granted).isFalse(); }
@Test public void should_rhs_not_be_evaluated_when_AND_operator_and_lhs_is_false___weak_ref() { when(lhs.isGranted(any(), any(), any(), anyString())).thenReturn(false); GrantEvaluator grantEvaluator = composer.and(lhs, rhs); boolean granted = grantEvaluator.isGranted(null, null, 1L, "my_type"); verify(lhs).isGranted(any(), any(), any(), anyString()); verifyZeroInteractions(rhs); assertThat(granted).isFalse(); }
@Test public void should_rhs_be_evaluated_when_AND_operator_and_lhs_is_true___strong_ref() { when(lhs.isGranted(any(), any(), any())).thenReturn(true); when(rhs.isGranted(any(), any(), any())).thenReturn(false); GrantEvaluator grantEvaluator = composer.and(lhs, rhs); boolean granted = grantEvaluator.isGranted(null, null, "fake"); verify(lhs).isGranted(any(), any(), any()); verify(rhs).isGranted(any(), any(), any()); assertThat(granted).isFalse(); }
@Test public void should_rhs_be_evaluated_when_AND_operator_and_lhs_is_true___weak_ref() { when(lhs.isGranted(any(), any(), any(), anyString())).thenReturn(true); when(rhs.isGranted(any(), any(), any(), anyString())).thenReturn(false); GrantEvaluator grantEvaluator = composer.and(lhs, rhs); boolean granted = grantEvaluator.isGranted(null, null, 1L, "my_type"); verify(lhs).isGranted(any(), any(), any(), anyString()); verify(rhs).isGranted(any(), any(), any(), anyString()); assertThat(granted).isFalse(); }