@Test public void testUnsetMask() { byte[] value = AccountAccessMask.setMask(new byte[0], AccountAccessMask.ACCESS_SKILL_QUEUE); value = AccountAccessMask.setMask(value, AccountAccessMask.ACCESS_ACCOUNT_BALANCE); Assert.assertTrue(AccountAccessMask.isValidMask(value)); for (AccountAccessMask next : AccountAccessMask.values()) { switch (next) { case ACCESS_SKILL_QUEUE: case ACCESS_ACCOUNT_BALANCE: Assert.assertTrue(AccountAccessMask.isAccessAllowed(value, next)); break; default: Assert.assertFalse(AccountAccessMask.isAccessAllowed(value, next)); } } }
@Test public void testIsAccessAllowedNo() { byte[] mask = AccountAccessMask.createMask( Arrays.asList( new AccountAccessMask[] { AccountAccessMask.ACCESS_ACCOUNT_BALANCE, AccountAccessMask.ACCESS_SKILL_QUEUE })); Assert.assertFalse( AccountAccessMask.isAccessAllowed(mask, AccountAccessMask.ACCESS_WALLET_JOURNAL)); }
@Test public void testIsAccessAllowedYes() { byte[] mask = AccountAccessMask.createMask( Arrays.asList( new AccountAccessMask[] { AccountAccessMask.ACCESS_ACCOUNT_BALANCE, AccountAccessMask.ACCESS_SKILL_QUEUE })); Assert.assertTrue( AccountAccessMask.isAccessAllowed(mask, AccountAccessMask.ACCESS_SKILL_QUEUE)); }
@Test public void testSetMask() { byte[] value = AccountAccessMask.setMask(new byte[0], AccountAccessMask.ACCESS_SKILL_QUEUE); Assert.assertTrue(AccountAccessMask.isValidMask(value)); Assert.assertTrue( AccountAccessMask.isAccessAllowed(value, AccountAccessMask.ACCESS_SKILL_QUEUE)); int val = AccountAccessMask.ACCESS_SKILL_QUEUE.getMaskValue(); int offset = val / 8; int bit = val % 8; for (int i = 0; i < value.length; i++) { if (i == offset) { Assert.assertEquals(1L << bit, value[i]); } else { Assert.assertEquals(0, value[i]); } } }