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

File IdGeneratorTest.java

 
testGenerateUniqueIdWhenInvalidNonAlphaPrefix: The prefix [a-b] should only contain alphanumerical chara...
testGenerateUniqueIdWhenInvalidEmptyPrefix: The prefix [] should only contain alphanumerical characte...
 

Code metrics

0
16
6
1
85
52
6
0.38
2.67
6
1

Classes

Class Line # Actions
IdGeneratorTest 33 16 0% 6 8
0.636363663.6%
 

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 org.xwiki.rendering.util;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.junit.rules.ExpectedException;
27   
28    /**
29    * Validate {@link IdGenerator}.
30    *
31    * @version $Id: 566df17083762cf0865ababfe641deaa16664fb2 $
32    */
 
33    public class IdGeneratorTest
34    {
35    private IdGenerator idGenerator;
36   
37    @Rule
38    public ExpectedException thrown = ExpectedException.none();
39   
 
40  5 toggle @Before
41    public void setUp() throws Exception
42    {
43  5 this.idGenerator = new IdGenerator();
44    }
45   
 
46  1 toggle @Test
47    public void testGenerateUniqueId()
48    {
49  1 Assert.assertEquals("Itext", this.idGenerator.generateUniqueId("text"));
50  1 Assert.assertEquals("Itext-1", this.idGenerator.generateUniqueId("te xt"));
51    }
52   
 
53  1 toggle @Test
54    public void testGenerateUniqueIdWithPrefix()
55    {
56  1 Assert.assertEquals("prefixtext", this.idGenerator.generateUniqueId("prefix", "text"));
57  1 Assert.assertEquals("prefixtext-1", this.idGenerator.generateUniqueId("prefix", "te xt"));
58    }
59   
 
60  1 toggle @Test
61    public void testGenerateUniqueIdFromNonAlphaNum()
62    {
63  1 Assert.assertEquals("I:_.-", this.idGenerator.generateUniqueId(":_.-"));
64  1 Assert.assertEquals("Iwithspace", this.idGenerator.generateUniqueId("with space"));
65  1 Assert.assertEquals("Iwithtab", this.idGenerator.generateUniqueId("with\ttab"));
66  1 Assert.assertEquals("I5BC67801", this.idGenerator.generateUniqueId("\u5BC6\u7801"));
67  1 Assert.assertEquals("I3D", this.idGenerator.generateUniqueId("="));
68    }
69   
 
70  0 toggle @Test
71    public void testGenerateUniqueIdWhenInvalidEmptyPrefix()
72    {
73  0 this.thrown.expect(IllegalArgumentException.class);
74  0 this.thrown.expectMessage("The prefix [] should only contain alphanumerical characters and not be empty.");
75  0 Test failure here this.idGenerator.generateUniqueId("", "whatever");
76    }
77   
 
78  0 toggle @Test
79    public void testGenerateUniqueIdWhenInvalidNonAlphaPrefix()
80    {
81  0 this.thrown.expect(IllegalArgumentException.class);
82  0 this.thrown.expectMessage("The prefix [a-b] should only contain alphanumerical characters and not be empty.");
83  0 Test failure here this.idGenerator.generateUniqueId("a-b", "whatever");
84    }
85    }