DubboParser { static @Nullable String method(Invocation invocation) { String methodName = invocation.getMethodName(); if ("$invoke".equals(methodName)) { Object[] arguments = invocation.getArguments(); if (arguments != null && arguments.length > 0 && arguments[0] instanceof String) { methodName = (String) arguments[0]; } else { methodName = null; } } return methodName != null && !methodName.isEmpty() ? methodName : null; }    }
@Test public void method() { when(invocation.getMethodName()).thenReturn("sayHello"); assertThat(DubboParser.method(invocation)) .isEqualTo("sayHello"); }
@Test public void method_malformed() { when(invocation.getMethodName()).thenReturn(""); assertThat(DubboParser.method(invocation)).isNull(); }
@Test public void method_invoke() { when(invocation.getMethodName()).thenReturn("$invoke"); when(invocation.getArguments()).thenReturn(new Object[] {"sayHello"}); assertThat(DubboParser.method(invocation)) .isEqualTo("sayHello"); }
@Test public void method_invoke_nullArgs() { when(invocation.getMethodName()).thenReturn("$invoke"); assertThat(DubboParser.method(invocation)).isNull(); }
@Test public void method_invoke_emptyArgs() { when(invocation.getMethodName()).thenReturn("$invoke"); when(invocation.getArguments()).thenReturn(new Object[0]); assertThat(DubboParser.method(invocation)).isNull(); }
@Test public void method_invoke_nonStringArg() { when(invocation.getMethodName()).thenReturn("$invoke"); when(invocation.getArguments()).thenReturn(new Object[] {new Object()}); assertThat(DubboParser.method(invocation)).isNull(); }