### Question:
Counter extends Applet { private void getBalance(APDU apdu, byte[] buffer) { Util.setShort(buffer, (byte) 0, balance); apdu.setOutgoingAndSend((byte) 0, (byte) 2); } private  Counter(); static void install(byte[] buffer, short offset, byte length); void process(APDU apdu); static final byte INS_GET_BALANCE; static final byte INS_CREDIT; static final byte INS_DEBIT; static final short MAX_BALANCE; static final short MAX_CREDIT; static final short MAX_DEBIT; }### Answer:
@Test public void balanceTest() throws CardException { assertArrayEquals(new byte[]{0x00, 0x00}, getBalance().getData()); }
@Test public void creditOverflowTest() throws CardException { sendCredit(OVERFLOW_CREDIT, ISO7816.SW_WRONG_DATA, new byte[]{}); sendCredit(MAX_CREDIT, 0x9000, MAX_CREDIT); assertArrayEquals(MAX_CREDIT, getBalance().getData()); }
@Test public void balanceOverflowTest() throws CardException { sendCredit(MAX_CREDIT, 0x9000, MAX_CREDIT); sendCredit(MAX_CREDIT, 0x9000, TestUtils.getByte(TestUtils.getInt(MAX_CREDIT) * 2)); sendCredit(new byte[]{0x00, 0x01}, ISO7816.SW_WRONG_DATA, new byte[]{}); assertArrayEquals(MAX_BALANCE, getBalance().getData()); }
@Test public void debitNegativeTest() throws CardException { sendCredit(new byte[]{0x00, 0x05}, 0x9000, new byte[]{0x00, 0x05}); assertArrayEquals(new byte[]{0x00, 0x05}, getBalance().getData()); sendDebit(new byte[]{0x00, 0x06}, ISO7816.SW_WRONG_DATA, new byte[]{}); assertArrayEquals(new byte[]{0x00, 0x05}, getBalance().getData()); }
@Test public void debitOverflowTest() throws CardException { sendDebit(new byte[]{0x00, 0x01}, ISO7816.SW_WRONG_DATA, new byte[]{}); assertArrayEquals(new byte[]{0x00, 0x00}, getBalance().getData()); }