You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by bd...@apache.org on 2016/07/11 21:04:32 UTC
[05/13] shiro git commit: SHIRO-395: Consolidated Publisher and
SubscriberRegistry interfaces into a single EventBus interface. The separate
interfaces were causing a lot of unnecessary complexity if you had a
component that need to both publish and sub
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/bus/EventListenerComparatorTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/bus/EventListenerComparatorTest.groovy b/core/src/test/groovy/org/apache/shiro/event/bus/EventListenerComparatorTest.groovy
deleted file mode 100644
index 1615e46..0000000
--- a/core/src/test/groovy/org/apache/shiro/event/bus/EventListenerComparatorTest.groovy
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.event.bus
-
-import static org.easymock.EasyMock.createStrictMock
-
-/**
- * @since 1.3
- */
-class EventListenerComparatorTest extends GroovyTestCase {
-
- EventListenerComparator comparator
-
- @Override
- protected void setUp() {
- comparator = new EventListenerComparator()
- }
-
- void testANull() {
- def result = comparator.compare(null, createStrictMock(EventListener))
- assertEquals(-1, result)
- }
-
- void testBNull() {
- def result = comparator.compare(createStrictMock(EventListener), null)
- assertEquals 1, result
- }
-
- void testBothNull() {
- assertEquals 0, comparator.compare(null, null)
- }
-
- void testBothSame() {
- def mock = createStrictMock(EventListener)
- assertEquals 0, comparator.compare(mock, mock)
- }
-
- void testBothEventListener() {
- def a = createStrictMock(EventListener)
- def b = createStrictMock(EventListener)
- assertEquals 0, comparator.compare(a, b)
- }
-
- void testATypedListenerBNormalListener() {
- def a = createStrictMock(TypedEventListener)
- def b = createStrictMock(EventListener)
- assertEquals(-1, comparator.compare(a, b))
- }
-
- void testANormalBTypedListener() {
- def a = createStrictMock(EventListener)
- def b = createStrictMock(TypedEventListener)
- assertEquals 1, comparator.compare(a, b)
- }
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/bus/ExceptionThrowingSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/bus/ExceptionThrowingSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/bus/ExceptionThrowingSubscriber.groovy
deleted file mode 100644
index b0b63c1..0000000
--- a/core/src/test/groovy/org/apache/shiro/event/bus/ExceptionThrowingSubscriber.groovy
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.event.bus
-
-import org.apache.shiro.event.Subscribe
-
-/**
- * @since 1.3
- */
-class ExceptionThrowingSubscriber extends TestSubscriber {
-
- @Subscribe
- void onEvent(ErrorCausingEvent event) {
- throw new UnsupportedOperationException("This throws!")
- }
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/bus/FooEvent.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/bus/FooEvent.groovy b/core/src/test/groovy/org/apache/shiro/event/bus/FooEvent.groovy
deleted file mode 100644
index b594c92..0000000
--- a/core/src/test/groovy/org/apache/shiro/event/bus/FooEvent.groovy
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.event.bus
-
-/**
- * @since 1.3
- */
-class FooEvent extends EventObject {
-
- FooEvent(Object o) {
- super(o)
- }
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/bus/NotAnnotatedSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/bus/NotAnnotatedSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/bus/NotAnnotatedSubscriber.groovy
deleted file mode 100644
index 8489185..0000000
--- a/core/src/test/groovy/org/apache/shiro/event/bus/NotAnnotatedSubscriber.groovy
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.event.bus
-
-/**
- * @since 1.3
- */
-class NotAnnotatedSubscriber {
- //not a subscriber - no methods have been annotated on purpose.
- void hello() {}
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/bus/SimpleEvent.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/bus/SimpleEvent.groovy b/core/src/test/groovy/org/apache/shiro/event/bus/SimpleEvent.groovy
deleted file mode 100644
index 9a8b1e4..0000000
--- a/core/src/test/groovy/org/apache/shiro/event/bus/SimpleEvent.groovy
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.event.bus
-
-/**
- * @since 1.3
- */
-class SimpleEvent {
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/bus/SimpleSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/bus/SimpleSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/bus/SimpleSubscriber.groovy
deleted file mode 100644
index 0fa44ea..0000000
--- a/core/src/test/groovy/org/apache/shiro/event/bus/SimpleSubscriber.groovy
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.event.bus
-
-import org.apache.shiro.event.Subscribe
-
-/**
- * @since 1.3
- */
-class SimpleSubscriber {
-
- int count
-
- SimpleSubscriber() {
- count = 0
- }
-
- @Subscribe
- void onEvent(SimpleEvent event) {
- count++
- }
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/bus/SingleArgumentMethodEventListenerTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/bus/SingleArgumentMethodEventListenerTest.groovy b/core/src/test/groovy/org/apache/shiro/event/bus/SingleArgumentMethodEventListenerTest.groovy
deleted file mode 100644
index bf3c060..0000000
--- a/core/src/test/groovy/org/apache/shiro/event/bus/SingleArgumentMethodEventListenerTest.groovy
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.event.bus
-
-import java.lang.reflect.Method
-
-/**
- * @since 1.3
- */
-class SingleArgumentMethodEventListenerTest extends GroovyTestCase {
-
- void testInvalidConstruction() {
-
- def target = new Object()
-
- def method = Object.class.getMethods()[0] //any old method will do
-
- try {
- //noinspection GroovyResultOfObjectAllocationIgnored
- new SingleArgumentMethodEventListener(target, method)
- fail("exception expected")
- } catch (IllegalArgumentException iae) {
- assertEquals iae.message, "Event handler methods must accept a single argument."
- }
- }
-
- void testValidConstruction() {
-
- def target = new TestSubscriber()
- def method = TestSubscriber.class.getMethods().find { it.name == "onFooEvent" }
-
- def listener = new SingleArgumentMethodEventListener(target, method)
-
- assertSame target, listener.getTarget()
- assertSame method, listener.getMethod()
- }
-
- void testMethodException() {
-
- def target = new TestSubscriber()
- def method = TestSubscriber.class.getMethods().find { it.name == "onFooEvent" }
-
- def listener = new SingleArgumentMethodEventListener(target, method) {
- @Override
- Method getMethod() {
- //sneakily swap out the valid method with an erroneous one. This wouldn't ever happen normally, we're
- //just doing this as a test harness:
- return Object.class.getMethods()[0] //any method will do
- }
- }
-
- //now invoke the erroneous method and ensure we get an exception:
- try {
- listener.onEvent(new FooEvent(this))
- fail("exception expected")
- } catch (IllegalStateException ise) {
- assertTrue ise.message.startsWith("Unable to invoke event handler method")
- }
- }
-
- void testAccepts() {
- def target = new TestSubscriber()
- def method = TestSubscriber.class.getMethods().find { it.name == "onFooEvent" }
-
- def listener = new SingleArgumentMethodEventListener(target, method)
-
- assertTrue listener.accepts(new FooEvent(this))
- }
-
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/bus/SubclassTestSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/bus/SubclassTestSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/bus/SubclassTestSubscriber.groovy
deleted file mode 100644
index 8dc717c..0000000
--- a/core/src/test/groovy/org/apache/shiro/event/bus/SubclassTestSubscriber.groovy
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.event.bus
-
-import org.apache.shiro.event.Subscribe
-
-/**
- * @since 1.3
- */
-class SubclassTestSubscriber extends TestSubscriber {
-
- int bazCount
-
- SubclassTestSubscriber() {
- bazCount = 0
- }
-
- @Subscribe
- void onEvent(BazEvent event) {
- bazCount++
- lastEvent = event;
- }
-
- @Subscribe
- void onEvent(ErrorCausingEvent event) {
- throw new UnsupportedOperationException("This throws!")
- }
-
- @Override
- int getCount() {
- return super.getCount() + bazCount
- }
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/bus/TestSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/bus/TestSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/bus/TestSubscriber.groovy
deleted file mode 100644
index 3de5488..0000000
--- a/core/src/test/groovy/org/apache/shiro/event/bus/TestSubscriber.groovy
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.shiro.event.bus
-
-import org.apache.shiro.event.Subscribe
-
-/**
- * @since 1.3
- */
-class TestSubscriber {
-
- int fooCount, barCount
- Object lastEvent;
-
- TestSubscriber() {
- fooCount = barCount = 0
- }
-
- @Subscribe
- void onFooEvent(FooEvent event) {
- fooCount++
- lastEvent = event;
- }
-
- @Subscribe
- void onBarEvent(BarEvent event) {
- barCount++
- lastEvent = event;
- }
-
- int getCount() {
- return fooCount + barCount
- }
-}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/AnnotationEventListenerResolverTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/AnnotationEventListenerResolverTest.groovy b/core/src/test/groovy/org/apache/shiro/event/support/AnnotationEventListenerResolverTest.groovy
new file mode 100644
index 0000000..fb5b1b4
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/AnnotationEventListenerResolverTest.groovy
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+/**
+ * @since 1.3
+ */
+class AnnotationEventListenerResolverTest extends GroovyTestCase {
+
+ void testSetGetAnnotationClass() {
+ def resolver = new AnnotationEventListenerResolver();
+ resolver.setAnnotationClass(Override.class) //any old annotation will do for the test
+ assertSame Override.class, resolver.getAnnotationClass()
+ }
+
+ void testNullInstanceArgument() {
+ def resolver = new AnnotationEventListenerResolver()
+ def collection = resolver.getEventListeners(null)
+ assertNotNull collection
+ assertTrue collection.isEmpty()
+ }
+
+ void testNoAnnotationsArgument() {
+ def resolver = new AnnotationEventListenerResolver()
+ def collection = resolver.getEventListeners(new NotAnnotatedSubscriber())
+ assertNotNull collection
+ assertTrue collection.isEmpty()
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/BarEvent.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/BarEvent.groovy b/core/src/test/groovy/org/apache/shiro/event/support/BarEvent.groovy
new file mode 100644
index 0000000..20d93e0
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/BarEvent.groovy
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+/**
+ * @since 1.3
+ */
+class BarEvent extends FooEvent {
+
+ BarEvent(Object o) {
+ super(o)
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/BazEvent.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/BazEvent.groovy b/core/src/test/groovy/org/apache/shiro/event/support/BazEvent.groovy
new file mode 100644
index 0000000..891e89e
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/BazEvent.groovy
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+/**
+ * @since 1.3
+ */
+class BazEvent extends BarEvent {
+
+ BazEvent(Object o) {
+ super(o)
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/ClassComparatorTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/ClassComparatorTest.groovy b/core/src/test/groovy/org/apache/shiro/event/support/ClassComparatorTest.groovy
new file mode 100644
index 0000000..1adb4f5
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/ClassComparatorTest.groovy
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+/**
+ * @since 1.3
+ */
+class ClassComparatorTest extends GroovyTestCase {
+
+ ClassComparator comparator
+
+ @Override
+ protected void setUp() {
+ comparator = new ClassComparator()
+ }
+
+ void testANull() {
+ def result = comparator.compare(null, Object)
+ assertEquals(-1, result)
+ }
+
+ void testBNull() {
+ def result = comparator.compare(Object, null)
+ assertEquals 1, result
+ }
+
+ void testBothNull() {
+ assertEquals 0, comparator.compare(null, null)
+ }
+
+ void testBothSame() {
+ assertEquals 0, comparator.compare(Object, Object)
+ }
+
+ void testAParentOfB() {
+ assertEquals 1, comparator.compare(Number, Integer)
+ }
+
+ void testBParentOfA() {
+ assertEquals(-1, comparator.compare(Integer, Number))
+ }
+
+ void testUnrelated() {
+ assertEquals(0, comparator.compare(Integer, Boolean))
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/DefaultEventBusTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/DefaultEventBusTest.groovy b/core/src/test/groovy/org/apache/shiro/event/support/DefaultEventBusTest.groovy
new file mode 100644
index 0000000..1f8d688
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/DefaultEventBusTest.groovy
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+import static org.easymock.EasyMock.*
+
+/**
+ * @since 1.3
+ */
+class DefaultEventBusTest extends GroovyTestCase {
+
+ DefaultEventBus bus;
+
+ @Override
+ protected void setUp() {
+ bus = new DefaultEventBus()
+ }
+
+ void testSetEventListenerResolver() {
+ def resolver = new EventListenerResolver() {
+ List<EventListener> getEventListeners(Object instance) {
+ return null //dummy implementation
+ }
+ }
+ bus.setEventListenerResolver(resolver)
+ assertSame resolver, bus.getEventListenerResolver()
+ }
+
+ void testSimpleSubscribe() {
+ def subscriber = new TestSubscriber();
+
+ bus.register(subscriber);
+
+ def event = new FooEvent(this)
+
+ bus.publish(event)
+
+ assertEquals 1, subscriber.fooCount
+ assertEquals 1, subscriber.count
+ assertSame event, subscriber.lastEvent
+ }
+
+ void testPublishNullEvent() {
+ def subscriber = new TestSubscriber();
+ bus.register(subscriber)
+
+ bus.publish(null)
+
+ assertEquals 0, subscriber.count
+ }
+
+ void testSubscribeNullInstance() {
+ def resolver = createStrictMock(EventListenerResolver) //assert no methods are called on this
+ bus.eventListenerResolver = resolver
+
+ replay(resolver)
+
+ bus.register(null)
+
+ verify(resolver)
+ }
+
+ void testSubscribeWithoutAnnotations() {
+ def subscriber = new NotAnnotatedSubscriber()
+ bus.register(subscriber)
+
+ bus.publish(new FooEvent(this))
+
+ assertEquals 0, bus.registry.size()
+ }
+
+ void testUnsubscribeNullInstance() {
+ bus.unregister(null)
+ }
+
+ void testUnsubscribe() {
+ def subscriber = new TestSubscriber()
+ bus.register(subscriber)
+ assertEquals 1, bus.registry.size()
+
+ def event = new FooEvent(this)
+
+ bus.publish(event)
+
+ assertSame event, subscriber.lastEvent
+ assertEquals 1, subscriber.fooCount
+ assertEquals 1, subscriber.count
+
+ bus.unregister(subscriber)
+
+ assertEquals 0, bus.registry.size()
+ }
+
+ void testPolymorphicSubscribeMethodsOnlyOneInvoked() {
+ def subscriber = new TestSubscriber()
+ bus.register(subscriber)
+
+ def event = new BarEvent(this)
+
+ bus.publish(event)
+
+ assertSame event, subscriber.lastEvent
+ assertEquals 0, subscriber.fooCount
+ assertEquals 1, subscriber.barCount
+ assertEquals 1, subscriber.count
+ }
+
+ void testPolymorphicSubscribeMethodsOnlyOneInvokedWithListenerSubclass() {
+ def subscriber = new SubclassTestSubscriber()
+ bus.register(subscriber)
+
+ def event = new BazEvent(this)
+
+ bus.publish(event)
+
+ assertSame event, subscriber.lastEvent
+ assertEquals 1, subscriber.count
+ assertEquals 1, subscriber.bazCount
+ assertEquals 0, subscriber.fooCount
+ assertEquals 0, subscriber.barCount
+ }
+
+ void testSubscribeWithErroneousAnnotation() {
+ def subscriber = new ErroneouslyAnnotatedSubscriber()
+ //noinspection GroovyUnusedCatchParameter
+ try {
+ bus.register(subscriber)
+ fail("exception expected")
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ void testContinueThroughListenerExceptions() {
+ def ok = new SimpleSubscriber()
+ def error = new ExceptionThrowingSubscriber()
+
+ bus.register(ok)
+ bus.register(error)
+
+ bus.publish(new ErrorCausingEvent())
+ bus.publish(new SimpleEvent())
+
+ assertEquals 1, ok.count
+ assertEquals 0, error.count
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/ErroneouslyAnnotatedSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/ErroneouslyAnnotatedSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/support/ErroneouslyAnnotatedSubscriber.groovy
new file mode 100644
index 0000000..66724a9
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/ErroneouslyAnnotatedSubscriber.groovy
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+import org.apache.shiro.event.Subscribe
+
+/**
+ * @since 1.3
+ */
+class ErroneouslyAnnotatedSubscriber {
+
+ @Subscribe
+ void onEvent(FooEvent event, Object someOtherArg) {
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/ErrorCausingEvent.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/ErrorCausingEvent.groovy b/core/src/test/groovy/org/apache/shiro/event/support/ErrorCausingEvent.groovy
new file mode 100644
index 0000000..177aa2a
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/ErrorCausingEvent.groovy
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+/**
+ * @since 1.3
+ */
+class ErrorCausingEvent {
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/EventListenerComparatorTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/EventListenerComparatorTest.groovy b/core/src/test/groovy/org/apache/shiro/event/support/EventListenerComparatorTest.groovy
new file mode 100644
index 0000000..8cae13f
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/EventListenerComparatorTest.groovy
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+import static org.easymock.EasyMock.createStrictMock
+
+/**
+ * @since 1.3
+ */
+class EventListenerComparatorTest extends GroovyTestCase {
+
+ EventListenerComparator comparator
+
+ @Override
+ protected void setUp() {
+ comparator = new EventListenerComparator()
+ }
+
+ void testANull() {
+ def result = comparator.compare(null, createStrictMock(EventListener))
+ assertEquals(-1, result)
+ }
+
+ void testBNull() {
+ def result = comparator.compare(createStrictMock(EventListener), null)
+ assertEquals 1, result
+ }
+
+ void testBothNull() {
+ assertEquals 0, comparator.compare(null, null)
+ }
+
+ void testBothSame() {
+ def mock = createStrictMock(EventListener)
+ assertEquals 0, comparator.compare(mock, mock)
+ }
+
+ void testBothEventListener() {
+ def a = createStrictMock(EventListener)
+ def b = createStrictMock(EventListener)
+ assertEquals 0, comparator.compare(a, b)
+ }
+
+ void testATypedListenerBNormalListener() {
+ def a = createStrictMock(TypedEventListener)
+ def b = createStrictMock(EventListener)
+ assertEquals(-1, comparator.compare(a, b))
+ }
+
+ void testANormalBTypedListener() {
+ def a = createStrictMock(EventListener)
+ def b = createStrictMock(TypedEventListener)
+ assertEquals 1, comparator.compare(a, b)
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/ExceptionThrowingSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/ExceptionThrowingSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/support/ExceptionThrowingSubscriber.groovy
new file mode 100644
index 0000000..4972cf0
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/ExceptionThrowingSubscriber.groovy
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+import org.apache.shiro.event.Subscribe
+
+/**
+ * @since 1.3
+ */
+class ExceptionThrowingSubscriber extends TestSubscriber {
+
+ @Subscribe
+ void onEvent(ErrorCausingEvent event) {
+ throw new UnsupportedOperationException("This throws!")
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/FooEvent.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/FooEvent.groovy b/core/src/test/groovy/org/apache/shiro/event/support/FooEvent.groovy
new file mode 100644
index 0000000..e7e2cf8
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/FooEvent.groovy
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+/**
+ * @since 1.3
+ */
+class FooEvent extends EventObject {
+
+ FooEvent(Object o) {
+ super(o)
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/NotAnnotatedSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/NotAnnotatedSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/support/NotAnnotatedSubscriber.groovy
new file mode 100644
index 0000000..591903b
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/NotAnnotatedSubscriber.groovy
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+/**
+ * @since 1.3
+ */
+class NotAnnotatedSubscriber {
+ //not a subscriber - no methods have been annotated on purpose.
+ void hello() {}
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/SimpleEvent.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/SimpleEvent.groovy b/core/src/test/groovy/org/apache/shiro/event/support/SimpleEvent.groovy
new file mode 100644
index 0000000..9f91c5a
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/SimpleEvent.groovy
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+/**
+ * @since 1.3
+ */
+class SimpleEvent {
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/SimpleSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/SimpleSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/support/SimpleSubscriber.groovy
new file mode 100644
index 0000000..601aa8b
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/SimpleSubscriber.groovy
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+import org.apache.shiro.event.Subscribe
+
+/**
+ * @since 1.3
+ */
+class SimpleSubscriber {
+
+ int count
+
+ SimpleSubscriber() {
+ count = 0
+ }
+
+ @Subscribe
+ void onEvent(SimpleEvent event) {
+ count++
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/SingleArgumentMethodEventListenerTest.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/SingleArgumentMethodEventListenerTest.groovy b/core/src/test/groovy/org/apache/shiro/event/support/SingleArgumentMethodEventListenerTest.groovy
new file mode 100644
index 0000000..56ef608
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/SingleArgumentMethodEventListenerTest.groovy
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+import java.lang.reflect.Method
+
+/**
+ * @since 1.3
+ */
+class SingleArgumentMethodEventListenerTest extends GroovyTestCase {
+
+ void testInvalidConstruction() {
+
+ def target = new Object()
+
+ def method = Object.class.getMethods()[0] //any old method will do
+
+ try {
+ //noinspection GroovyResultOfObjectAllocationIgnored
+ new SingleArgumentMethodEventListener(target, method)
+ fail("exception expected")
+ } catch (IllegalArgumentException iae) {
+ assertEquals iae.message, "Event handler methods must accept a single argument."
+ }
+ }
+
+ void testValidConstruction() {
+
+ def target = new TestSubscriber()
+ def method = TestSubscriber.class.getMethods().find { it.name == "onFooEvent" }
+
+ def listener = new SingleArgumentMethodEventListener(target, method)
+
+ assertSame target, listener.getTarget()
+ assertSame method, listener.getMethod()
+ }
+
+ void testMethodException() {
+
+ def target = new TestSubscriber()
+ def method = TestSubscriber.class.getMethods().find { it.name == "onFooEvent" }
+
+ def listener = new SingleArgumentMethodEventListener(target, method) {
+ @Override
+ Method getMethod() {
+ //sneakily swap out the valid method with an erroneous one. This wouldn't ever happen normally, we're
+ //just doing this as a test harness:
+ return Object.class.getMethods()[0] //any method will do
+ }
+ }
+
+ //now invoke the erroneous method and ensure we get an exception:
+ try {
+ listener.onEvent(new FooEvent(this))
+ fail("exception expected")
+ } catch (IllegalStateException ise) {
+ assertTrue ise.message.startsWith("Unable to invoke event handler method")
+ }
+ }
+
+ void testAccepts() {
+ def target = new TestSubscriber()
+ def method = TestSubscriber.class.getMethods().find { it.name == "onFooEvent" }
+
+ def listener = new SingleArgumentMethodEventListener(target, method)
+
+ assertTrue listener.accepts(new FooEvent(this))
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/SubclassTestSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/SubclassTestSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/support/SubclassTestSubscriber.groovy
new file mode 100644
index 0000000..629c024
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/SubclassTestSubscriber.groovy
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+import org.apache.shiro.event.Subscribe
+
+/**
+ * @since 1.3
+ */
+class SubclassTestSubscriber extends TestSubscriber {
+
+ int bazCount
+
+ SubclassTestSubscriber() {
+ bazCount = 0
+ }
+
+ @Subscribe
+ void onEvent(BazEvent event) {
+ bazCount++
+ lastEvent = event;
+ }
+
+ @Subscribe
+ void onEvent(ErrorCausingEvent event) {
+ throw new UnsupportedOperationException("This throws!")
+ }
+
+ @Override
+ int getCount() {
+ return super.getCount() + bazCount
+ }
+}
http://git-wip-us.apache.org/repos/asf/shiro/blob/bdecc0ba/core/src/test/groovy/org/apache/shiro/event/support/TestSubscriber.groovy
----------------------------------------------------------------------
diff --git a/core/src/test/groovy/org/apache/shiro/event/support/TestSubscriber.groovy b/core/src/test/groovy/org/apache/shiro/event/support/TestSubscriber.groovy
new file mode 100644
index 0000000..de75c31
--- /dev/null
+++ b/core/src/test/groovy/org/apache/shiro/event/support/TestSubscriber.groovy
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.event.support
+
+import org.apache.shiro.event.Subscribe
+
+/**
+ * @since 1.3
+ */
+class TestSubscriber {
+
+ int fooCount, barCount
+ Object lastEvent;
+
+ TestSubscriber() {
+ fooCount = barCount = 0
+ }
+
+ @Subscribe
+ void onFooEvent(FooEvent event) {
+ fooCount++
+ lastEvent = event;
+ }
+
+ @Subscribe
+ void onBarEvent(BarEvent event) {
+ barCount++
+ lastEvent = event;
+ }
+
+ int getCount() {
+ return fooCount + barCount
+ }
+}