1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.internal

File AbstractNotifyOnUpdateListTest.java

 

Code metrics

2
69
8
2
176
116
9
0.13
8.62
4
1.12

Classes

Class Line # Actions
AbstractNotifyOnUpdateListTest 38 66 0% 6 0
1.0100%
AbstractNotifyOnUpdateListTest.NotifyOnUpdateList 43 3 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 5 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 com.xpn.xwiki.internal;
21   
22    import static org.junit.Assert.*;
23   
24    import java.util.ArrayList;
25    import java.util.Arrays;
26    import java.util.Iterator;
27    import java.util.LinkedList;
28    import java.util.List;
29    import java.util.ListIterator;
30   
31    import org.junit.Test;
32   
33    /**
34    * Unit tests for {@link AbstractNotifyOnUpdateList}.
35    *
36    * @version $Id: 9a5dc135ef7ef4268917c2741c182f50f27bb1af $
37    */
 
38    public class AbstractNotifyOnUpdateListTest
39    {
40    /**
41    * The concrete {@link AbstractNotifyOnUpdateList} implementation used in tests.
42    */
 
43    private static class NotifyOnUpdateList extends AbstractNotifyOnUpdateList<Integer>
44    {
45    private int counter;
46   
 
47  5 toggle protected NotifyOnUpdateList(List<Integer> list)
48    {
49  5 super(list);
50    }
51   
 
52  14 toggle @Override
53    protected void onUpdate()
54    {
55  14 counter++;
56    }
57   
 
58  22 toggle public int getCounter()
59    {
60  22 return counter;
61    }
62    }
63   
 
64  1 toggle @Test
65    public void testUpdate()
66    {
67  1 int expectedCounter = 0;
68  1 NotifyOnUpdateList list = new NotifyOnUpdateList(new ArrayList<Integer>());
69  1 assertEquals(expectedCounter, list.getCounter());
70   
71  1 list.add(13);
72  1 assertEquals(++expectedCounter, list.getCounter());
73   
74  1 list.add(0, 27);
75  1 assertEquals(++expectedCounter, list.getCounter());
76   
77  1 assertTrue(list.contains(13));
78  1 assertFalse(list.isEmpty());
79  1 assertEquals(2, list.size());
80   
81  1 list.clear();
82  1 assertEquals(++expectedCounter, list.getCounter());
83  1 assertTrue(list.isEmpty());
84  1 assertEquals(0, list.size());
85   
86  1 assertFalse(list.contains(27));
87   
88  1 list.addAll(Arrays.asList(1, 2));
89  1 assertEquals(++expectedCounter, list.getCounter());
90  1 assertEquals(2, list.size());
91   
92  1 assertTrue(list.containsAll(Arrays.asList(2, 1)));
93   
94  1 assertEquals(Arrays.asList(1, 2), list);
95  1 assertNotEquals(Arrays.asList(2, 1), list);
96   
97  1 list.remove(Integer.valueOf(3));
98  1 assertEquals(expectedCounter, list.getCounter());
99   
100  1 list.remove(Integer.valueOf(1));
101  1 assertEquals(++expectedCounter, list.getCounter());
102   
103  1 list.removeAll(Arrays.asList(3, 2));
104  1 assertEquals(++expectedCounter, list.getCounter());
105   
106  1 list.addAll(0, Arrays.asList(4, 5));
107  1 assertEquals(++expectedCounter, list.getCounter());
108   
109  1 list.removeAll(Arrays.asList(3, 2));
110  1 assertEquals(expectedCounter, list.getCounter());
111   
112  1 list.retainAll(Arrays.asList(5, 4, 3));
113  1 assertEquals(expectedCounter, list.getCounter());
114   
115  1 list.retainAll(Arrays.asList(5, 6));
116  1 assertEquals(++expectedCounter, list.getCounter());
117   
118  1 list.set(0, 25);
119  1 assertEquals(++expectedCounter, list.getCounter());
120    }
121   
 
122  1 toggle @Test
123    public void testToString()
124    {
125  1 List<Integer> list = Arrays.asList(3, 2, 1);
126  1 assertEquals(list.toString(), new NotifyOnUpdateList(list).toString());
127    }
128   
 
129  1 toggle @Test
130    public void testSubList()
131    {
132  1 int expectedCounter = 0;
133  1 NotifyOnUpdateList list = new NotifyOnUpdateList(Arrays.asList(5, 4, 3, 2, 1));
134  1 assertEquals(expectedCounter, list.getCounter());
135   
136  1 List<Integer> subList = list.subList(1, 4);
137  1 subList.set(0, 16);
138  1 assertEquals(++expectedCounter, list.getCounter());
139    }
140   
 
141  1 toggle @Test
142    public void testIterator()
143    {
144  1 int expectedCounter = 0;
145  1 NotifyOnUpdateList list = new NotifyOnUpdateList(new LinkedList<Integer>(Arrays.asList(1, 2)));
146  1 assertEquals(expectedCounter, list.getCounter());
147   
148  1 Iterator<Integer> iterator = list.iterator();
149  3 while (iterator.hasNext()) {
150  2 iterator.next();
151  2 iterator.remove();
152  2 assertEquals(++expectedCounter, list.getCounter());
153    }
154  1 assertTrue(list.isEmpty());
155  1 assertEquals(2, list.getCounter());
156    }
157   
 
158  1 toggle @Test
159    public void testListIterator()
160    {
161  1 int expectedCounter = 0;
162  1 NotifyOnUpdateList list = new NotifyOnUpdateList(new LinkedList<Integer>(Arrays.asList(8, 7)));
163  1 assertEquals(expectedCounter, list.getCounter());
164   
165  1 ListIterator<Integer> listIterator = list.listIterator();
166  1 listIterator.next();
167  1 listIterator.set(9);
168  1 assertEquals(++expectedCounter, list.getCounter());
169   
170  1 listIterator.next();
171  1 listIterator.add(10);
172  1 assertEquals(++expectedCounter, list.getCounter());
173   
174  1 assertEquals(Arrays.asList(9, 7, 10), list);
175    }
176    }