SignalsRequestParser { public static SignalRequest[] parse(String request) throws MgcpParseException { String[] signals = request.split("\\),"); SignalRequest[] signalRequests = new SignalRequest[signals.length]; for (int i = 0; i < signals.length; i++) { signalRequests[i] = parseSingle(signals[i].trim() + ")"); } return signalRequests; }  static SignalRequest[] parse(String request);  }
@Test public void testParseSingleRequest() throws MgcpParseException { final String request = "AU/pa(an=https: SignalRequest[] requests = SignalsRequestParser.parse(request); assertEquals(1, requests.length); assertEquals("AU", requests[0].getPackageName()); assertEquals("pa", requests[0].getSignalType()); assertEquals("https: assertEquals("1", requests[0].getParameter("it")); }
@Test public void testParseMultipleRequests() throws MgcpParseException { final String request = "AU/pa(an=https: SignalRequest[] requests = SignalsRequestParser.parse(request); assertEquals(2, requests.length); assertEquals("AU", requests[0].getPackageName()); assertEquals("pa", requests[0].getSignalType()); assertEquals("https: assertEquals("1", requests[0].getParameter("it")); assertEquals("AU", requests[1].getPackageName()); assertEquals("pr", requests[1].getSignalType()); assertEquals("https: assertNull(requests[1].getParameter("it")); }
@Test(expected = MgcpParseException.class) public void testParseWhenMissingPackageNameSeparator() throws MgcpParseException { final String request = "AUpa(an=https: SignalsRequestParser.parse(request); }
@Test(expected = MgcpParseException.class) public void testParseWhenMissingParameterStartSeparator() throws MgcpParseException { final String request = "AU/pa an=https: SignalsRequestParser.parse(request); }
@Test(expected = MgcpParseException.class) public void testParseWhenMissingParameterValueSeparator() throws MgcpParseException { final String request = "AU/pa(an=https: SignalsRequestParser.parse(request); }
@Test(expected = MgcpParseException.class) public void testParseWhenMissingParameters() throws MgcpParseException { final String request = "AU/pa()"; SignalsRequestParser.parse(request); }