1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.observation

File WrappedThreadEventListenerTest.java

 

Code metrics

0
31
5
1
103
64
5
0.16
6.2
5
1

Classes

Class Line # Actions
WrappedThreadEventListenerTest 31 31 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.observation;
21   
22    import org.junit.jupiter.api.Test;
23    import org.mockito.Mockito;
24    import org.xwiki.observation.event.AllEvent;
25   
26    /**
27    * Unit tests for {@link WrappedThreadEventListener}.
28    *
29    * @version $Id: a9c46e3d2a921f48c8d576e5a92370e8ceff6229 $
30    */
 
31    public class WrappedThreadEventListenerTest
32    {
33    private EventListener listenermock = Mockito.mock(EventListener.class);
34   
 
35  1 toggle @Test
36    public void testWrapp()
37    {
38  1 WrappedThreadEventListener wrapper = new WrappedThreadEventListener(this.listenermock);
39   
40  1 wrapper.getName();
41  1 Mockito.verify(this.listenermock).getName();
42   
43  1 wrapper.getEvents();
44  1 Mockito.verify(this.listenermock).getEvents();
45    }
46   
 
47  1 toggle @Test
48    public void testOnEventOnCurrentThread() throws InterruptedException
49    {
50  1 final WrappedThreadEventListener wrapper = new WrappedThreadEventListener(this.listenermock);
51   
52  1 Runnable runnable = new Runnable()
53    {
 
54  2 toggle @Override
55    public void run()
56    {
57  2 wrapper.onEvent(AllEvent.ALLEVENT, null, null);
58    }
59    };
60   
61  1 Thread thread = new Thread(runnable);
62  1 thread.start();
63  1 thread.join();
64  1 Mockito.verify(this.listenermock, Mockito.times(0)).onEvent(AllEvent.ALLEVENT, null, null);
65   
66  1 wrapper.onEvent(AllEvent.ALLEVENT, null, null);
67  1 Mockito.verify(this.listenermock).onEvent(AllEvent.ALLEVENT, null, null);
68   
69  1 thread = new Thread(runnable);
70  1 thread.start();
71  1 thread.join();
72  1 Mockito.verify(this.listenermock).onEvent(AllEvent.ALLEVENT, null, null);
73    }
74   
 
75  1 toggle @Test
76    public void testOnEventOnPassedThread() throws InterruptedException
77    {
78  1 final WrappedThreadEventListener wrapper =
79    new WrappedThreadEventListener(this.listenermock, Thread.currentThread());
80   
81  1 Runnable runnable = new Runnable()
82    {
 
83  2 toggle @Override
84    public void run()
85    {
86  2 wrapper.onEvent(AllEvent.ALLEVENT, null, null);
87    }
88    };
89   
90  1 Thread thread = new Thread(runnable);
91  1 thread.start();
92  1 thread.join();
93  1 Mockito.verify(this.listenermock, Mockito.times(0)).onEvent(AllEvent.ALLEVENT, null, null);
94   
95  1 wrapper.onEvent(AllEvent.ALLEVENT, null, null);
96  1 Mockito.verify(this.listenermock).onEvent(AllEvent.ALLEVENT, null, null);
97   
98  1 thread = new Thread(runnable);
99  1 thread.start();
100  1 thread.join();
101  1 Mockito.verify(this.listenermock).onEvent(AllEvent.ALLEVENT, null, null);
102    }
103    }