modules/base/src/test/java/test/com/sun/javafx/event/CompositeEventHandlerTest.java

Print this page
rev 9235 : 8134760: Refactor Javafx base module tests for clear separation of tests
Reviewed-by:


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.event;
  27 




  28 import javafx.event.Event;
  29 import javafx.event.WeakEventHandler;
  30 import javafx.event.WeakEventHandlerUtil;
  31 import org.junit.Assert;
  32 
  33 import org.junit.Before;
  34 import org.junit.Test;
  35 
  36 public class CompositeEventHandlerTest {
  37     private CompositeEventHandler<Event> compositeEventHandler;
  38 
  39     @Before
  40     public void setUp() {
  41         compositeEventHandler = new CompositeEventHandler<Event>();
  42     }
  43 
  44     @Test
  45     public void weakEventHandlerTest() {
  46         final EventCountingHandler<Event> eventCountingHandler =
  47                 new EventCountingHandler<Event>();
  48         final WeakEventHandler<Event> weakEventHandler =
  49                 new WeakEventHandler<Event>(eventCountingHandler);
  50 
  51         compositeEventHandler.addEventHandler(weakEventHandler);
  52         
  53         Assert.assertTrue(
  54                 compositeEventHandler.containsHandler(weakEventHandler));
  55         compositeEventHandler.dispatchCapturingEvent(new EmptyEvent());
  56         Assert.assertEquals(0, eventCountingHandler.getEventCount());
  57         compositeEventHandler.dispatchBubblingEvent(new EmptyEvent());
  58         Assert.assertEquals(1, eventCountingHandler.getEventCount());
  59 
  60         WeakEventHandlerUtil.clear(weakEventHandler);
  61 
  62         Assert.assertFalse(
  63                 compositeEventHandler.containsHandler(weakEventHandler));
  64         compositeEventHandler.dispatchCapturingEvent(new EmptyEvent());
  65         Assert.assertEquals(1, eventCountingHandler.getEventCount());
  66         compositeEventHandler.dispatchBubblingEvent(new EmptyEvent());
  67         Assert.assertEquals(1, eventCountingHandler.getEventCount());
  68     }
  69 
  70     @Test
  71     public void weakEventFilterTest() {
  72         final EventCountingHandler<Event> eventCountingFilter =
  73                 new EventCountingHandler<Event>();
  74         final WeakEventHandler<Event> weakEventFilter =
  75                 new WeakEventHandler<Event>(eventCountingFilter);
  76 
  77         compositeEventHandler.addEventFilter(weakEventFilter);
  78 
  79         Assert.assertTrue(
  80                 compositeEventHandler.containsFilter(weakEventFilter));
  81         compositeEventHandler.dispatchCapturingEvent(new EmptyEvent());
  82         Assert.assertEquals(1, eventCountingFilter.getEventCount());
  83         compositeEventHandler.dispatchBubblingEvent(new EmptyEvent());
  84         Assert.assertEquals(1, eventCountingFilter.getEventCount());
  85 
  86         WeakEventHandlerUtil.clear(weakEventFilter);
  87 
  88         Assert.assertFalse(
  89                 compositeEventHandler.containsFilter(weakEventFilter));
  90         compositeEventHandler.dispatchCapturingEvent(new EmptyEvent());
  91         Assert.assertEquals(1, eventCountingFilter.getEventCount());
  92         compositeEventHandler.dispatchBubblingEvent(new EmptyEvent());
  93         Assert.assertEquals(1, eventCountingFilter.getEventCount());
  94     }
  95 }


   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.com.sun.javafx.event;
  27 
  28 import com.sun.javafx.event.CompositeEventHandler;
  29 import com.sun.javafx.event.CompositeEventHandlerShim;
  30 import test.com.sun.javafx.event.EventCountingHandler;
  31 import test.com.sun.javafx.event.EmptyEvent;
  32 import javafx.event.Event;
  33 import javafx.event.WeakEventHandler;
  34 import javafx.event.WeakEventHandlerUtil;
  35 import org.junit.Assert;
  36 
  37 import org.junit.Before;
  38 import org.junit.Test;
  39 
  40 public class CompositeEventHandlerTest {
  41     private CompositeEventHandler<Event> compositeEventHandler;
  42 
  43     @Before
  44     public void setUp() {
  45         compositeEventHandler = new CompositeEventHandler<Event>();
  46     }
  47 
  48     @Test
  49     public void weakEventHandlerTest() {
  50         final EventCountingHandler<Event> eventCountingHandler =
  51                 new EventCountingHandler<Event>();
  52         final WeakEventHandler<Event> weakEventHandler =
  53                 new WeakEventHandler<Event>(eventCountingHandler);
  54 
  55         compositeEventHandler.addEventHandler(weakEventHandler);
  56         
  57         Assert.assertTrue(
  58             CompositeEventHandlerShim.containsHandler(compositeEventHandler, weakEventHandler));
  59         compositeEventHandler.dispatchCapturingEvent(new EmptyEvent());
  60         Assert.assertEquals(0, eventCountingHandler.getEventCount());
  61         compositeEventHandler.dispatchBubblingEvent(new EmptyEvent());
  62         Assert.assertEquals(1, eventCountingHandler.getEventCount());
  63 
  64         WeakEventHandlerUtil.clear(weakEventHandler);
  65 
  66         Assert.assertFalse(
  67                 CompositeEventHandlerShim.containsHandler(compositeEventHandler, weakEventHandler));
  68         compositeEventHandler.dispatchCapturingEvent(new EmptyEvent());
  69         Assert.assertEquals(1, eventCountingHandler.getEventCount());
  70         compositeEventHandler.dispatchBubblingEvent(new EmptyEvent());
  71         Assert.assertEquals(1, eventCountingHandler.getEventCount());
  72     }
  73 
  74     @Test
  75     public void weakEventFilterTest() {
  76         final EventCountingHandler<Event> eventCountingFilter =
  77                 new EventCountingHandler<Event>();
  78         final WeakEventHandler<Event> weakEventFilter =
  79                 new WeakEventHandler<Event>(eventCountingFilter);
  80 
  81         compositeEventHandler.addEventFilter(weakEventFilter);
  82 
  83         Assert.assertTrue(
  84                 CompositeEventHandlerShim.containsFilter(compositeEventHandler, weakEventFilter));
  85         compositeEventHandler.dispatchCapturingEvent(new EmptyEvent());
  86         Assert.assertEquals(1, eventCountingFilter.getEventCount());
  87         compositeEventHandler.dispatchBubblingEvent(new EmptyEvent());
  88         Assert.assertEquals(1, eventCountingFilter.getEventCount());
  89 
  90         WeakEventHandlerUtil.clear(weakEventFilter);
  91 
  92         Assert.assertFalse(
  93                 CompositeEventHandlerShim.containsFilter(compositeEventHandler, weakEventFilter));
  94         compositeEventHandler.dispatchCapturingEvent(new EmptyEvent());
  95         Assert.assertEquals(1, eventCountingFilter.getEventCount());
  96         compositeEventHandler.dispatchBubblingEvent(new EmptyEvent());
  97         Assert.assertEquals(1, eventCountingFilter.getEventCount());
  98     }
  99 }