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

File ReferenceHandlerTest.java

 

Code metrics

0
15
8
2
117
54
8
0.53
1.88
4
1

Classes

Class Line # Actions
ReferenceHandlerTest 28 10 0% 3 0
1.0100%
ReferenceHandlerTest.TestReferenceHandler 61 5 0% 5 1
0.990%
 

Contributing tests

This file is covered by 2 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.wikimodel;
21   
22    import junit.framework.TestCase;
23   
24    /**
25    * @version $Id: eab27e6afb54e3f6ab352d636182482379bc3133 $
26    * @since 4.0M1
27    */
 
28    public class ReferenceHandlerTest extends TestCase
29    {
30    private TestReferenceHandler clazz;
31   
 
32  2 toggle protected void setUp() throws Exception
33    {
34  2 super.setUp();
35  2 this.clazz = new TestReferenceHandler(true, true);
36    }
37   
 
38  1 toggle public void testHandleImageUppercase()
39    {
40  1 WikiReference ref = new WikiReference("Image:foo.png", "bar");
41  1 clazz.handle(ref);
42  1 assertEquals("foo.png", clazz.getImgRef());
43  1 assertEquals("bar", clazz.getImgLabel());
44    }
45   
 
46  1 toggle public void testHandleImageLowercase()
47    {
48  1 WikiReference ref = new WikiReference("image:bar.png", "foo");
49  1 clazz.handle(ref);
50  1 assertEquals("bar.png", clazz.getImgRef());
51  1 assertEquals("foo", clazz.getImgLabel());
52    }
53   
54    /*
55    * ========================================================================
56    */
57   
58    /**
59    * @author mkirst(at portolancs dot com)
60    */
 
61    private static class TestReferenceHandler extends ReferenceHandler
62    {
63    private String imgRef;
64   
65    private String imgLabel;
66   
 
67  2 toggle protected TestReferenceHandler(boolean supportImage,
68    boolean supportDownload)
69    {
70  2 super(supportImage, supportDownload);
71    }
72   
73    /*
74    * (non-Javadoc)
75    *
76    * @see ReferenceHandler#handleImage(java.lang.String,
77    * java.lang.String, WikiParameters)
78    */
 
79  2 toggle @Override
80    protected void handleImage(String ref, String label,
81    WikiParameters params)
82    {
83  2 imgRef = ref;
84  2 imgLabel = label;
85    }
86   
87    /*
88    * (non-Javadoc)
89    *
90    * @see
91    * ReferenceHandler#handleReference(java.lang.String,
92    * java.lang.String, WikiParameters)
93    */
 
94  0 toggle @Override
95    protected void handleReference(String ref, String label,
96    WikiParameters params)
97    {
98    // not interested in.
99    }
100   
101    /**
102    * @return the imgRef
103    */
 
104  2 toggle public String getImgRef()
105    {
106  2 return imgRef;
107    }
108   
109    /**
110    * @return the imgLabel
111    */
 
112  2 toggle public String getImgLabel()
113    {
114  2 return imgLabel;
115    }
116    }
117    }