1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.observation

File WrappedThreadEventListenerTest.java

 

Code metrics

0
31
5
1
100
64
5
0.16
6.2
5
1

Classes

Class Line # Actions
WrappedThreadEventListenerTest 26 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.Test;
23    import org.mockito.Mockito;
24    import org.xwiki.observation.event.AllEvent;
25   
 
26    public class WrappedThreadEventListenerTest
27    {
28    private EventListener listenermock = Mockito.mock(EventListener.class);
29   
30    // Tests
31   
 
32  1 toggle @Test
33    public void testWrapp()
34    {
35  1 WrappedThreadEventListener wrapper = new WrappedThreadEventListener(this.listenermock);
36   
37  1 wrapper.getName();
38  1 Mockito.verify(this.listenermock).getName();
39   
40  1 wrapper.getEvents();
41  1 Mockito.verify(this.listenermock).getEvents();
42    }
43   
 
44  1 toggle @Test
45    public void testOnEventOnCurrentThread() throws InterruptedException
46    {
47  1 final WrappedThreadEventListener wrapper = new WrappedThreadEventListener(this.listenermock);
48   
49  1 Runnable runnable = new Runnable()
50    {
 
51  2 toggle @Override
52    public void run()
53    {
54  2 wrapper.onEvent(AllEvent.ALLEVENT, null, null);
55    }
56    };
57   
58  1 Thread thread = new Thread(runnable);
59  1 thread.start();
60  1 thread.join();
61  1 Mockito.verify(this.listenermock, Mockito.times(0)).onEvent(AllEvent.ALLEVENT, null, null);
62   
63  1 wrapper.onEvent(AllEvent.ALLEVENT, null, null);
64  1 Mockito.verify(this.listenermock).onEvent(AllEvent.ALLEVENT, null, null);
65   
66  1 thread = new Thread(runnable);
67  1 thread.start();
68  1 thread.join();
69  1 Mockito.verify(this.listenermock).onEvent(AllEvent.ALLEVENT, null, null);
70    }
71   
 
72  1 toggle @Test
73    public void testOnEventOnPassedThread() throws InterruptedException
74    {
75  1 final WrappedThreadEventListener wrapper =
76    new WrappedThreadEventListener(this.listenermock, Thread.currentThread());
77   
78  1 Runnable runnable = new Runnable()
79    {
 
80  2 toggle @Override
81    public void run()
82    {
83  2 wrapper.onEvent(AllEvent.ALLEVENT, null, null);
84    }
85    };
86   
87  1 Thread thread = new Thread(runnable);
88  1 thread.start();
89  1 thread.join();
90  1 Mockito.verify(this.listenermock, Mockito.times(0)).onEvent(AllEvent.ALLEVENT, null, null);
91   
92  1 wrapper.onEvent(AllEvent.ALLEVENT, null, null);
93  1 Mockito.verify(this.listenermock).onEvent(AllEvent.ALLEVENT, null, null);
94   
95  1 thread = new Thread(runnable);
96  1 thread.start();
97  1 thread.join();
98  1 Mockito.verify(this.listenermock).onEvent(AllEvent.ALLEVENT, null, null);
99    }
100    }