@Test
    public void testParser() throws GuacamoleException {

        // Build buffer containing all of the instruction test cases, one after
        // the other
        StringBuilder allTestCases = new StringBuilder();
        for (TestCase testCase : TEST_CASES)
            allTestCases.append(testCase.UNPARSED);

        // Prepare buffer and offsets for feeding the data into the parser as
        // if received over the network
        char buffer[] = allTestCases.toString().toCharArray();
        int offset = 0;
        int length = buffer.length;

        // Verify that each of the expected instructions is received in order
        for (TestCase testCase : TEST_CASES) {

            // Feed data into parser until parser refuses to receive more data
            int parsed;
            while (length > 0 && (parsed = parser.append(buffer, offset, length)) != 0) {
                offset += parsed;
                length -= parsed;
            }

            // An instruction should now be parsed and ready for retrieval
            assertTrue(parser.hasNext());

            // Verify instruction contains expected opcode and args
            GuacamoleInstruction instruction = parser.next();
            assertNotNull(instruction);
            assertEquals(testCase.OPCODE, instruction.getOpcode());
            assertEquals(testCase.ARGS, instruction.getArgs());

        }

        // There should be no more instructions
        assertFalse(parser.hasNext());

    }
Verify that GuacamoleParser correctly parses each of the instruction
test cases included in the GuacamoleInstruction test.

@throws GuacamoleException
    If a parse error occurs.
guacamole-common/src/test/java/org/apache/guacamole/protocol/GuacamoleParserTest.java