You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2014/03/22 20:51:56 UTC
svn commit: r1580304 - in
/tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/observer:
./ ObserverManagerTest.java
Author: dblevins
Date: Sat Mar 22 19:51:56 2014
New Revision: 1580304
URL: http://svn.apache.org/r1580304
Log:
Test that would have passed prior to this week's reworking of ObserverManager
Added:
tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/observer/
tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/observer/ObserverManagerTest.java (with props)
Added: tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/observer/ObserverManagerTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/observer/ObserverManagerTest.java?rev=1580304&view=auto
==============================================================================
--- tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/observer/ObserverManagerTest.java (added)
+++ tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/observer/ObserverManagerTest.java Sat Mar 22 19:51:56 2014
@@ -0,0 +1,111 @@
+/*
+ * 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.openejb.observer;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+public class ObserverManagerTest extends Assert {
+
+ private final ObserverManager observers = new ObserverManager();
+ private final List<String> observed = new ArrayList<String>();
+
+ @Before
+ public void setup() {
+ observers.addObserver(new BasicObserver());
+ }
+
+ @Test
+ @Ignore("Passed with previous ObserverManager, now fails")
+ public void canObserveObject() throws Exception {
+ observers.fireEvent("");
+ assertEvent(BasicObserver.object);
+ }
+
+ @Test
+ @Ignore("Passed with previous ObserverManager, now fails")
+ public void objectNotInvoked() throws Exception {
+ observers.fireEvent(new Color());
+ assertEvent(BasicObserver.color);
+ }
+
+ @Test
+ @Ignore("Passed with previous ObserverManager, now fails")
+ public void observeEmerald() throws Exception {
+ observers.fireEvent(new Emerald());
+ assertEvent(BasicObserver.emerald);
+ }
+
+
+ public static class Color {
+ }
+
+ public static class Green extends Color {
+ }
+
+ public static class Emerald extends Green {
+ }
+
+
+ public class BasicObserver {
+
+ private static final String color = "color";
+ private static final String object = "object";
+ private static final String emerald = "emerald";
+
+ public void observe(@Observes Object event) {
+ observed.add(object);
+ }
+
+ public void observe(@Observes Color event) {
+ observed.add(color);
+ }
+
+ public void observe(@Observes Emerald event) {
+ observed.add(emerald);
+ }
+ }
+
+
+ private void assertEvent(String... expected) {
+ assertEquals(join(expected), join(observed));
+ }
+
+ public static String join(final Object... collection) {
+ return join(Arrays.asList(collection));
+ }
+
+ public static String join(final Collection<?> collection) {
+ final String delimiter = "\n";
+ if (collection.size() == 0) {
+ return "";
+ }
+ final StringBuilder sb = new StringBuilder();
+ for (final Object obj : collection) {
+ sb.append(obj).append(delimiter);
+ }
+ return sb.substring(0, sb.length() - delimiter.length());
+ }
+
+}
Propchange: tomee/tomee/trunk/container/openejb-loader/src/test/java/org/apache/openejb/observer/ObserverManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native