MethodId { public static MethodId fromIdentifier(String identifier) throws ClassNotFoundException { final String[] splitIdentifier = identifier.split(UNDERSCORE); final MethodId generatedMethodId = new MethodId(); try { generatedMethodId.className = splitIdentifier[0]; generatedMethodId.methodName = splitIdentifier[1]; generatedMethodId.returnType = splitIdentifier[2]; } catch (ArrayIndexOutOfBoundsException e) { throw new MalformedIdentifierException("Malformed identifier : " + identifier); } if (splitIdentifier.length > 3 ) { generatedMethodId.parameterTypes = new Class<?>[splitIdentifier.length - 3]; for (int i = 3; i < splitIdentifier.length ; i++) { generatedMethodId.parameterTypes[splitIdentifier.length-i-1] = Class.forName(splitIdentifier[i]); } } return generatedMethodId; } private  MethodId();  MethodId(Method method); static MethodId fromIdentifier(String identifier); String getPrefix(); String getClassName(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); String getMethodName(); Class<?>[] getParameterTypes(); static final String UNDERSCORE; }
@Test public void testCreationFromGivenIdentifier() throws Exception { final MethodId generated = MethodId.fromIdentifier("com.flipkart.flux.client.intercept.SimpleWorkflowForTest_simpleStringModifyingTask_com.flipkart.flux.client.intercept.SimpleWorkflowForTest.StringEvent_com.flipkart.flux.client.intercept.SimpleWorkflowForTest$StringEvent"); final MethodId expected = new MethodId(new SimpleWorkflowForTest().getClass().getDeclaredMethod("simpleStringModifyingTask", SimpleWorkflowForTest.StringEvent.class)); assertThat(generated).isEqualTo(expected); }
@Test(expected = MalformedIdentifierException.class) public void testCreationFromIdentifier_shouldBombOnMalformedIdentifiers() throws Exception { MethodId.fromIdentifier("badIdentifier_withOnlyOneUnderscore"); }