MockInvoker implements Invoker<T> { public static String normalizeMock(String mock) { if (mock == null) { return mock; } mock = mock.trim(); if (mock.length() == 0) { return mock; } if (RETURN_KEY.equalsIgnoreCase(mock)) { return RETURN_PREFIX + "null"; } if (ConfigUtils.isDefault(mock) || "fail".equalsIgnoreCase(mock) || "force".equalsIgnoreCase(mock)) { return "default"; } if (mock.startsWith(FAIL_PREFIX)) { mock = mock.substring(FAIL_PREFIX.length()).trim(); } if (mock.startsWith(FORCE_PREFIX)) { mock = mock.substring(FORCE_PREFIX.length()).trim(); } if (mock.startsWith(RETURN_PREFIX) || mock.startsWith(THROW_PREFIX)) { mock = mock.replace('`', '"'); } return mock; } MockInvoker(URL url, Class<T> type); static Object parseMockValue(String mock); static Object parseMockValue(String mock, Type[] returnTypes); @Override Result invoke(Invocation invocation); static Throwable getThrowable(String throwstr); @SuppressWarnings("unchecked") static Object getMockObject(String mockService, Class serviceType); static String normalizeMock(String mock); @Override URL getUrl(); @Override boolean isAvailable(); @Override void destroy(); @Override Class<T> getInterface();  }
@Test public void testNormalizeMock() { Assertions.assertNull(MockInvoker.normalizeMock(null)); Assertions.assertEquals("", MockInvoker.normalizeMock("")); Assertions.assertEquals("", MockInvoker.normalizeMock("fail:")); Assertions.assertEquals("", MockInvoker.normalizeMock("force:")); Assertions.assertEquals("throw", MockInvoker.normalizeMock("throw")); Assertions.assertEquals("default", MockInvoker.normalizeMock("fail")); Assertions.assertEquals("default", MockInvoker.normalizeMock("force")); Assertions.assertEquals("default", MockInvoker.normalizeMock("true")); Assertions.assertEquals("default", MockInvoker.normalizeMock("default")); Assertions.assertEquals("return null", MockInvoker.normalizeMock("return")); Assertions.assertEquals("return null", MockInvoker.normalizeMock("return null")); }