@Test(expected = IllegalArgumentException.class) public void testAddListener_InvalidSubjectWildcardInMiddle() { tree.addListener(listener, "org.motechproject.*.event"); }
public void addListener(EventListener listener, String subject) { if (subject == null) { throw new IllegalArgumentException("Cannot add listener for null subject"); } int asteriskLocation = subject.indexOf('*'); if (asteriskLocation != -1 && (asteriskLocation + 1) != subject.length()) { throw new IllegalArgumentException("Wildcard must be last element of subject: " + subject); } if (subject.contains("..")) { throw new IllegalArgumentException("Subject can not contain an empty path segment: " + subject); } String[] path = subject.split(SPLIT_REGEX); if (path[path.length - 1].contains("*") && path[path.length - 1].length() > 1) { throw new IllegalArgumentException("Wildcard can not be mixed with characters"); } if ("*".equals(subject)) { addListener(listener); return; } EventListenerTree child = getChild(path[0]); if (child == null) { child = new EventListenerTree(path[0], this); addChild(child); } child.addListener(listener, path, 0); }
EventListenerTree { public void addListener(EventListener listener, String subject) { if (subject == null) { throw new IllegalArgumentException("Cannot add listener for null subject"); } int asteriskLocation = subject.indexOf('*'); if (asteriskLocation != -1 && (asteriskLocation + 1) != subject.length()) { throw new IllegalArgumentException("Wildcard must be last element of subject: " + subject); } if (subject.contains("..")) { throw new IllegalArgumentException("Subject can not contain an empty path segment: " + subject); } String[] path = subject.split(SPLIT_REGEX); if (path[path.length - 1].contains("*") && path[path.length - 1].length() > 1) { throw new IllegalArgumentException("Wildcard can not be mixed with characters"); } if ("*".equals(subject)) { addListener(listener); return; } EventListenerTree child = getChild(path[0]); if (child == null) { child = new EventListenerTree(path[0], this); addChild(child); } child.addListener(listener, path, 0); } }
EventListenerTree { public void addListener(EventListener listener, String subject) { if (subject == null) { throw new IllegalArgumentException("Cannot add listener for null subject"); } int asteriskLocation = subject.indexOf('*'); if (asteriskLocation != -1 && (asteriskLocation + 1) != subject.length()) { throw new IllegalArgumentException("Wildcard must be last element of subject: " + subject); } if (subject.contains("..")) { throw new IllegalArgumentException("Subject can not contain an empty path segment: " + subject); } String[] path = subject.split(SPLIT_REGEX); if (path[path.length - 1].contains("*") && path[path.length - 1].length() > 1) { throw new IllegalArgumentException("Wildcard can not be mixed with characters"); } if ("*".equals(subject)) { addListener(listener); return; } EventListenerTree child = getChild(path[0]); if (child == null) { child = new EventListenerTree(path[0], this); addChild(child); } child.addListener(listener, path, 0); } EventListenerTree();  EventListenerTree(String pathElement, EventListenerTree parent); }
EventListenerTree { public void addListener(EventListener listener, String subject) { if (subject == null) { throw new IllegalArgumentException("Cannot add listener for null subject"); } int asteriskLocation = subject.indexOf('*'); if (asteriskLocation != -1 && (asteriskLocation + 1) != subject.length()) { throw new IllegalArgumentException("Wildcard must be last element of subject: " + subject); } if (subject.contains("..")) { throw new IllegalArgumentException("Subject can not contain an empty path segment: " + subject); } String[] path = subject.split(SPLIT_REGEX); if (path[path.length - 1].contains("*") && path[path.length - 1].length() > 1) { throw new IllegalArgumentException("Wildcard can not be mixed with characters"); } if ("*".equals(subject)) { addListener(listener); return; } EventListenerTree child = getChild(path[0]); if (child == null) { child = new EventListenerTree(path[0], this); addChild(child); } child.addListener(listener, path, 0); } EventListenerTree();  EventListenerTree(String pathElement, EventListenerTree parent); String getPathElement(); String getSubject(); void addListener(EventListener listener, String subject); Set<EventListener> getListeners(String subject); boolean hasListener(String subject); int getListenerCount(String subject); void removeAllListeners(String beanName); }
EventListenerTree { public void addListener(EventListener listener, String subject) { if (subject == null) { throw new IllegalArgumentException("Cannot add listener for null subject"); } int asteriskLocation = subject.indexOf('*'); if (asteriskLocation != -1 && (asteriskLocation + 1) != subject.length()) { throw new IllegalArgumentException("Wildcard must be last element of subject: " + subject); } if (subject.contains("..")) { throw new IllegalArgumentException("Subject can not contain an empty path segment: " + subject); } String[] path = subject.split(SPLIT_REGEX); if (path[path.length - 1].contains("*") && path[path.length - 1].length() > 1) { throw new IllegalArgumentException("Wildcard can not be mixed with characters"); } if ("*".equals(subject)) { addListener(listener); return; } EventListenerTree child = getChild(path[0]); if (child == null) { child = new EventListenerTree(path[0], this); addChild(child); } child.addListener(listener, path, 0); } EventListenerTree();  EventListenerTree(String pathElement, EventListenerTree parent); String getPathElement(); String getSubject(); void addListener(EventListener listener, String subject); Set<EventListener> getListeners(String subject); boolean hasListener(String subject); int getListenerCount(String subject); void removeAllListeners(String beanName);  }