Clover icon

Magnolia Imaging Module 3.2.3

  1. Project Clover database Fri Nov 6 2015 14:54:03 CET
  2. Package info.magnolia.imaging.util

File PathSplitterTest.java

 

Code metrics

0
85
18
1
205
144
18
0.21
4.72
18
1

Classes

Class Line # Actions
PathSplitterTest 43 85 0% 18 0
1.0100%
 

Contributing tests

This file is covered by 18 tests. .

Source view

1    /**
2    * This file Copyright (c) 2009-2015 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.imaging.util;
35   
36    import static org.junit.Assert.assertEquals;
37   
38    import org.junit.Test;
39   
40    /**
41    * Tests for {@link info.magnolia.imaging.util.PathSplitter}.
42    */
 
43    public class PathSplitterTest {
44   
 
45  1 toggle @Test
46    public void testEmptyStringYieldsNoResults() {
47  1 assertEquals(0, new PathSplitter("").count());
48  1 assertEquals("", new PathSplitter("").next());
49  1 assertEquals("", new PathSplitter("").skipTo(0));
50  1 assertEquals("", new PathSplitter("").remaining());
51    }
52   
 
53  1 toggle @Test
54    public void testNullsAreHandledGracefullyCauseWeAreThatNice() {
55  1 assertEquals(0, new PathSplitter(null).count());
56  1 assertEquals("", new PathSplitter(null).next());
57  1 assertEquals("", new PathSplitter(null).skipTo(0));
58  1 assertEquals("", new PathSplitter(null).remaining());
59    }
60   
 
61  1 toggle @Test
62    public void testLeadingAndTralingslahesAreIgnored() {
63  1 PathSplitter ps = new PathSplitter("/foo/bar");
64  1 assertEquals(2, ps.count());
65  1 assertEquals("foo", ps.next());
66  1 assertEquals("bar", ps.next());
67   
68  1 ps = new PathSplitter("/foo/bar/");
69  1 assertEquals(2, ps.count());
70  1 assertEquals("foo", ps.next());
71  1 assertEquals("bar", ps.next());
72   
73  1 ps = new PathSplitter("foo/bar/");
74  1 assertEquals(2, ps.count());
75  1 assertEquals("foo", ps.next());
76  1 assertEquals("bar", ps.next());
77    }
78   
 
79  1 toggle @Test
80    public void testEmptyElementsMatter() {
81  1 final PathSplitter ps = new PathSplitter("/foo//bar/");
82  1 assertEquals(3, ps.count());
83  1 assertEquals("foo", ps.skipTo(0));
84  1 assertEquals("", ps.skipTo(1));
85  1 assertEquals("bar", ps.skipTo(2));
86    }
87   
88    // although maybe this isn't desired ?
 
89  1 toggle @Test
90    public void testEmptyElementsBeforeTrailingSlashWorkToo() {
91  1 final PathSplitter ps = new PathSplitter("/foo/bar//");
92  1 assertEquals(3, ps.count());
93  1 assertEquals("foo", ps.skipTo(0));
94  1 assertEquals("bar", ps.skipTo(1));
95  1 assertEquals("", ps.skipTo(2));
96    }
97   
98    // although maybe this isn't desired ?
 
99  1 toggle @Test
100    public void testEmptyElementsAfterLeadingSlashWorkToo() {
101  1 final PathSplitter ps = new PathSplitter("//foo/bar/");
102  1 assertEquals(3, ps.count());
103  1 assertEquals("", ps.skipTo(0));
104  1 assertEquals("foo", ps.skipTo(1));
105  1 assertEquals("bar", ps.skipTo(2));
106    }
107   
 
108  1 toggle @Test
109    public void testDocumentedExample() {
110  1 final PathSplitter ps = new PathSplitter("/foo/bar/baz/a/b/c/d/e");
111  1 assertEquals(8, ps.count());
112  1 assertEquals("baz", ps.skipTo(2));
113  1 assertEquals("a", ps.next());
114  1 assertEquals("b/c/d/e", ps.remaining());
115    }
116   
 
117  1 toggle @Test
118    public void testRemainingCanBeCalledFromTheStartEvenIfThisSeemsQuiteUseless() {
119  1 assertEquals("foo/bar/baz/a/b/c/d/e", new PathSplitter("/foo/bar/baz/a/b/c/d/e").remaining());
120    }
121   
 
122  1 toggle @Test
123    public void testRemainingCanBeCalledEvenIfWeAlreadyReachedTheLastElement() {
124  1 final PathSplitter ps = new PathSplitter("/foo/bar");
125  1 assertEquals("bar", ps.skipTo(1));
126  1 assertEquals("", ps.remaining());
127    }
128   
 
129  1 toggle @Test
130    public void testExtensionIsTrimmedByDefault() {
131  1 final PathSplitter ps = new PathSplitter("/foo/bar.html");
132  1 assertEquals(2, ps.count());
133  1 assertEquals("bar", ps.skipTo(1));
134  1 assertEquals("", ps.remaining());
135    }
136   
 
137  1 toggle @Test
138    public void testExtensionCanBeKeptAndIsNotCountingAsAnElement() {
139  1 final PathSplitter ps = new PathSplitter("/foo/bar.html", '/', false);
140  1 assertEquals(2, ps.count());
141  1 assertEquals("foo", ps.next());
142  1 assertEquals("bar.html", ps.next());
143  1 assertEquals("", ps.remaining());
144    }
145   
 
146  1 toggle @Test
147    public void testDotsInPathNotAtTheEndAreNotTrimmed() {
148  1 final PathSplitter ps = new PathSplitter("/foo.something/bar", '/', true);
149  1 assertEquals(2, ps.count());
150  1 assertEquals("foo.something", ps.next());
151  1 assertEquals("bar", ps.next());
152  1 assertEquals("", ps.remaining());
153    }
154   
 
155  1 toggle @Test
156    public void testOnlyOneToSplit() {
157  1 final PathSplitter ps = new PathSplitter("foo", '/', true);
158  1 assertEquals(1, ps.count());
159  1 assertEquals("foo", ps.next());
160  1 assertEquals("", ps.next());
161  1 assertEquals("", ps.remaining());
162    }
163   
 
164  1 toggle @Test
165    public void testDotsInPathOnlyOneToSplit() {
166  1 final PathSplitter ps = new PathSplitter("/foo.ext", '/', false);
167  1 assertEquals(1, ps.count());
168  1 assertEquals("foo.ext", ps.next());
169  1 assertEquals("", ps.next());
170  1 assertEquals("", ps.remaining());
171    }
172   
 
173  1 toggle @Test
174    public void testDotsInPathOnlyOneToSplitTrimExtension() {
175  1 final PathSplitter ps = new PathSplitter("foo.ext/", '/', true);
176  1 assertEquals(1, ps.count());
177  1 assertEquals("foo", ps.next());
178  1 assertEquals("", ps.next());
179  1 assertEquals("", ps.remaining());
180    }
181   
 
182  1 toggle @Test
183    public void testDotsInNames() {
184  1 final PathSplitter ps = new PathSplitter("/foo.foo.foo/bar.ext", false);
185  1 assertEquals("foo.foo.foo", ps.next());
186  1 assertEquals("bar.ext", ps.skipTo(1));
187  1 assertEquals("", ps.remaining());
188    }
189   
 
190  1 toggle @Test
191    public void testNextAndSkipCallsDontOverlapEachOther() {
192  1 final PathSplitter ps = new PathSplitter("/foo/bar");
193  1 assertEquals("foo", ps.next());
194  1 assertEquals("bar", ps.skipTo(1));
195  1 assertEquals("", ps.remaining());
196    }
197   
 
198  1 toggle @Test
199    public void testTrimExtensionProperly() {
200  1 final PathSplitter ps = new PathSplitter("/foo/bar.baz.extension", true);
201  1 assertEquals("foo", ps.next());
202  1 assertEquals("bar.baz", ps.skipTo(1));
203  1 assertEquals("", ps.remaining());
204    }
205    }