### Question:
AbstractRegistry implements Registry { @Override public void subscribe(URL url, NotifyListener listener) { if (url == null) { throw new IllegalArgumentException("subscribe url == null"); } if (listener == null) { throw new IllegalArgumentException("subscribe listener == null"); } if (logger.isInfoEnabled()) { logger.info("Subscribe: " + url); } Set<NotifyListener> listeners = subscribed.computeIfAbsent(url, k -> { return new ConcurrentHashSet<>(); }); listeners.add(listener); } AbstractRegistry(URL url); @Override URL getUrl(); Set<URL> getRegistered(); Map<URL, Set<NotifyListener>> getSubscribed(); Map<URL, Map<String, List<URL>>> getNotified(); File getCacheFile(); Properties getCacheProperties(); AtomicLong getLastCacheChanged(); void doSaveProperties(long version); List<URL> getCacheUrls(URL url); @Override List<URL> lookup(URL url); @Override void register(URL url); @Override void unregister(URL url); @Override void subscribe(URL url, NotifyListener listener); @Override void unsubscribe(URL url, NotifyListener listener); @Override void destroy(); @Override String toString();  }### Answer:
@Test public void testSubscribeIfUrlNull() throws Exception { Assertions.assertThrows(IllegalArgumentException.class, () -> { final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false); NotifyListener listener = urls -> notified.set(Boolean.TRUE); URL url = new URL("dubbo", "192.168.0.1", 2200); abstractRegistry.subscribe(null, listener); Assertions.fail("subscribe url == null"); }); }
@Test public void testSubscribeIfListenerNull() throws Exception { Assertions.assertThrows(IllegalArgumentException.class, () -> { final AtomicReference<Boolean> notified = new AtomicReference<Boolean>(false); NotifyListener listener = urls -> notified.set(Boolean.TRUE); URL url = new URL("dubbo", "192.168.0.1", 2200); abstractRegistry.subscribe(url, null); Assertions.fail("listener url == null"); }); }
@Test public void testSubscribe() throws Exception { try { abstractRegistry.subscribe(testUrl, null); Assertions.fail(); } catch (Exception e) { Assertions.assertTrue(e instanceof IllegalArgumentException); } try { abstractRegistry.subscribe(null, null); Assertions.fail(); } catch (Exception e) { Assertions.assertTrue(e instanceof IllegalArgumentException); } Assertions.assertNull(abstractRegistry.getSubscribed().get(testUrl)); abstractRegistry.subscribe(testUrl, listener); Assertions.assertNotNull(abstractRegistry.getSubscribed().get(testUrl)); Assertions.assertTrue(abstractRegistry.getSubscribed().get(testUrl).contains(listener)); }