@RunWith(MockitoJUnitRunner.class)
public class PermissionTest {
private static final boolean ACCEPT = true;
private static final boolean DENY = false;
private static final boolean FRIEND = true;
private static final boolean NOT_FRIEND = false;
@Test
public void hasPermissionWhenFriend() {
givenFriendCondition(FRIEND);
boolean permission = dut.hasPermission();
assertThat(permission, is(ACCEPT));
}
@Test
public void hasPermissionWhenNotFriend() {
givenFriendCondition(NOT_FRIEND);
boolean permission = dut.hasPermission();
assertThat(permission, is(DENY));
}
private void givenFriendCondition(boolean areFriends) {
when(daoProvider.get("key")).thenReturn(dao);
when(dao.areFriends("id")).thenReturn(areFriends);
}
}