### Question:
InjvmProtocol extends AbstractProtocol implements Protocol { public boolean isInjvmRefer(URL url) { final boolean isJvmRefer; String scope = url.getParameter(Constants.SCOPE_KEY); if (Constants.LOCAL_PROTOCOL.toString().equals(url.getProtocol())) { isJvmRefer = false; } else if (Constants.SCOPE_LOCAL.equals(scope) || (url.getParameter(Constants.LOCAL_PROTOCOL, false))) { isJvmRefer = true; } else if (Constants.SCOPE_REMOTE.equals(scope)) { isJvmRefer = false; } else if (url.getParameter(Constants.GENERIC_KEY, false)) { isJvmRefer = false; } else if (getExporter(exporterMap, url) != null) { isJvmRefer = true; } else { isJvmRefer = false; } return isJvmRefer; } InjvmProtocol(); static InjvmProtocol getInjvmProtocol(); @Override int getDefaultPort(); @Override Exporter<T> export(Invoker<T> invoker); @Override Invoker<T> refer(Class<T> serviceType, URL url); boolean isInjvmRefer(URL url); static final String NAME; static final int DEFAULT_PORT; }### Answer:
@Test public void testIsInjvmRefer() throws Exception { DemoService service = new DemoServiceImpl(); URL url = URL.valueOf("injvm: .addParameter(Constants.INTERFACE_KEY, DemoService.class.getName()); Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url)); exporters.add(exporter); url = url.setProtocol("dubbo"); assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); url = url.addParameter(Constants.GROUP_KEY, "*") .addParameter(Constants.VERSION_KEY, "*"); assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); url = URL.valueOf("fake: assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); url = URL.valueOf("fake: assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); url = URL.valueOf("fake: assertFalse(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); url = URL.valueOf("fake: assertFalse(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url)); }