AgencyIdSupport { public static String getAgencyIdFromEntityId(String entityId) throws InvalidArgumentServiceException { int index = entityId.indexOf('_'); if (index == -1) throw new InvalidArgumentServiceException("entityId", "badEntityId"); return entityId.substring(0, index); }  static String getAgencyIdFromEntityId(String entityId);  }
@Test public void test() throws InvalidArgumentServiceException { assertEquals("a", AgencyIdSupport.getAgencyIdFromEntityId("a_b")); assertEquals("b", AgencyIdSupport.getAgencyIdFromEntityId("b_c_d")); try { AgencyIdSupport.getAgencyIdFromEntityId("ab"); fail(); } catch (InvalidArgumentServiceException ex) { } }