### Question:
ConditionRouter extends AbstractRouter implements Comparable<Router> { boolean matchWhen(URL url, Invocation invocation) { return CollectionUtils.isEmptyMap(whenCondition) || matchCondition(whenCondition, url, null, invocation); } ConditionRouter(String rule, boolean force, boolean enabled);  ConditionRouter(URL url); void init(String rule); @Override List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation); @Override boolean isRuntime(); @Override URL getUrl(); static final String NAME; }### Answer:
@Test public void testRoute_matchWhen() { Invocation invocation = new RpcInvocation(); Router router = new ConditionRouterFactory().getRouter(getRouteUrl(" => host = 1.2.3.4")); boolean matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer: Assertions.assertEquals(true, matchWhen); router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4")); matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer: Assertions.assertEquals(true, matchWhen); router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.1,3.3.3.3 & host !=1.1.1.1 => host = 1.2.3.4")); matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer: Assertions.assertEquals(false, matchWhen); router = new ConditionRouterFactory().getRouter(getRouteUrl("host !=4.4.4.4 & host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4")); matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer: Assertions.assertEquals(true, matchWhen); router = new ConditionRouterFactory().getRouter(getRouteUrl("host !=4.4.4.* & host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4")); matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer: Assertions.assertEquals(true, matchWhen); router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.*,3.3.3.3 & host != 1.1.1.1 => host = 1.2.3.4")); matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer: Assertions.assertEquals(false, matchWhen); router = new ConditionRouterFactory().getRouter(getRouteUrl("host = 2.2.2.2,1.1.1.*,3.3.3.3 & host != 1.1.1.2 => host = 1.2.3.4")); matchWhen = ((ConditionRouter) router).matchWhen(URL.valueOf("consumer: Assertions.assertEquals(true, matchWhen); }