Clover icon

Magnolia Imaging Module 3.4.2-SUPPORT-10161

  1. Project Clover database Tue Jul 16 2019 23:33:19 EEST
  2. Package info.magnolia.imaging.util

File PathSplitterTest.java

 

Code metrics

0
85
18
1
202
144
18
0.21
4.72
18
1

Classes

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

Contributing tests

This file is covered by 18 tests. .

Source view

1    /**
2    * This file Copyright (c) 2009-2018 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    public class PathSplitterTest {
41   
 
42  1 toggle @Test
43    public void emptyStringYieldsNoResults() {
44  1 assertEquals(0, new PathSplitter("").count());
45  1 assertEquals("", new PathSplitter("").next());
46  1 assertEquals("", new PathSplitter("").skipTo(0));
47  1 assertEquals("", new PathSplitter("").remaining());
48    }
49   
 
50  1 toggle @Test
51    public void nullsAreHandledGracefullyCauseWeAreThatNice() {
52  1 assertEquals(0, new PathSplitter(null).count());
53  1 assertEquals("", new PathSplitter(null).next());
54  1 assertEquals("", new PathSplitter(null).skipTo(0));
55  1 assertEquals("", new PathSplitter(null).remaining());
56    }
57   
 
58  1 toggle @Test
59    public void leadingAndTrailingSlashesAreIgnored() {
60  1 PathSplitter ps = new PathSplitter("/foo/bar");
61  1 assertEquals(2, ps.count());
62  1 assertEquals("foo", ps.next());
63  1 assertEquals("bar", ps.next());
64   
65  1 ps = new PathSplitter("/foo/bar/");
66  1 assertEquals(2, ps.count());
67  1 assertEquals("foo", ps.next());
68  1 assertEquals("bar", ps.next());
69   
70  1 ps = new PathSplitter("foo/bar/");
71  1 assertEquals(2, ps.count());
72  1 assertEquals("foo", ps.next());
73  1 assertEquals("bar", ps.next());
74    }
75   
 
76  1 toggle @Test
77    public void emptyElementsMatter() {
78  1 final PathSplitter ps = new PathSplitter("/foo//bar/");
79  1 assertEquals(3, ps.count());
80  1 assertEquals("foo", ps.skipTo(0));
81  1 assertEquals("", ps.skipTo(1));
82  1 assertEquals("bar", ps.skipTo(2));
83    }
84   
85    // although maybe this isn't desired ?
 
86  1 toggle @Test
87    public void emptyElementsBeforeTrailingSlashWorkToo() {
88  1 final PathSplitter ps = new PathSplitter("/foo/bar//");
89  1 assertEquals(3, ps.count());
90  1 assertEquals("foo", ps.skipTo(0));
91  1 assertEquals("bar", ps.skipTo(1));
92  1 assertEquals("", ps.skipTo(2));
93    }
94   
95    // although maybe this isn't desired ?
 
96  1 toggle @Test
97    public void emptyElementsAfterLeadingSlashWorkToo() {
98  1 final PathSplitter ps = new PathSplitter("//foo/bar/");
99  1 assertEquals(3, ps.count());
100  1 assertEquals("", ps.skipTo(0));
101  1 assertEquals("foo", ps.skipTo(1));
102  1 assertEquals("bar", ps.skipTo(2));
103    }
104   
 
105  1 toggle @Test
106    public void documentedExample() {
107  1 final PathSplitter ps = new PathSplitter("/foo/bar/baz/a/b/c/d/e");
108  1 assertEquals(8, ps.count());
109  1 assertEquals("baz", ps.skipTo(2));
110  1 assertEquals("a", ps.next());
111  1 assertEquals("b/c/d/e", ps.remaining());
112    }
113   
 
114  1 toggle @Test
115    public void remainingCanBeCalledFromTheStartEvenIfThisSeemsQuiteUseless() {
116  1 assertEquals("foo/bar/baz/a/b/c/d/e", new PathSplitter("/foo/bar/baz/a/b/c/d/e").remaining());
117    }
118   
 
119  1 toggle @Test
120    public void remainingCanBeCalledEvenIfWeAlreadyReachedTheLastElement() {
121  1 final PathSplitter ps = new PathSplitter("/foo/bar");
122  1 assertEquals("bar", ps.skipTo(1));
123  1 assertEquals("", ps.remaining());
124    }
125   
 
126  1 toggle @Test
127    public void extensionIsTrimmedByDefault() {
128  1 final PathSplitter ps = new PathSplitter("/foo/bar.html");
129  1 assertEquals(2, ps.count());
130  1 assertEquals("bar", ps.skipTo(1));
131  1 assertEquals("", ps.remaining());
132    }
133   
 
134  1 toggle @Test
135    public void extensionCanBeKeptAndIsNotCountingAsAnElement() {
136  1 final PathSplitter ps = new PathSplitter("/foo/bar.html", '/', false);
137  1 assertEquals(2, ps.count());
138  1 assertEquals("foo", ps.next());
139  1 assertEquals("bar.html", ps.next());
140  1 assertEquals("", ps.remaining());
141    }
142   
 
143  1 toggle @Test
144    public void dotsInPathNotAtTheEndAreNotTrimmed() {
145  1 final PathSplitter ps = new PathSplitter("/foo.something/bar", '/', true);
146  1 assertEquals(2, ps.count());
147  1 assertEquals("foo.something", ps.next());
148  1 assertEquals("bar", ps.next());
149  1 assertEquals("", ps.remaining());
150    }
151   
 
152  1 toggle @Test
153    public void onlyOneToSplit() {
154  1 final PathSplitter ps = new PathSplitter("foo", '/', true);
155  1 assertEquals(1, ps.count());
156  1 assertEquals("foo", ps.next());
157  1 assertEquals("", ps.next());
158  1 assertEquals("", ps.remaining());
159    }
160   
 
161  1 toggle @Test
162    public void dotsInPathOnlyOneToSplit() {
163  1 final PathSplitter ps = new PathSplitter("/foo.ext", '/', false);
164  1 assertEquals(1, ps.count());
165  1 assertEquals("foo.ext", ps.next());
166  1 assertEquals("", ps.next());
167  1 assertEquals("", ps.remaining());
168    }
169   
 
170  1 toggle @Test
171    public void dotsInPathOnlyOneToSplitTrimExtension() {
172  1 final PathSplitter ps = new PathSplitter("foo.ext/", '/', true);
173  1 assertEquals(1, ps.count());
174  1 assertEquals("foo", ps.next());
175  1 assertEquals("", ps.next());
176  1 assertEquals("", ps.remaining());
177    }
178   
 
179  1 toggle @Test
180    public void dotsInNames() {
181  1 final PathSplitter ps = new PathSplitter("/foo.foo.foo/bar.ext", false);
182  1 assertEquals("foo.foo.foo", ps.next());
183  1 assertEquals("bar.ext", ps.skipTo(1));
184  1 assertEquals("", ps.remaining());
185    }
186   
 
187  1 toggle @Test
188    public void nextAndSkipCallsDontOverlapEachOther() {
189  1 final PathSplitter ps = new PathSplitter("/foo/bar");
190  1 assertEquals("foo", ps.next());
191  1 assertEquals("bar", ps.skipTo(1));
192  1 assertEquals("", ps.remaining());
193    }
194   
 
195  1 toggle @Test
196    public void trimExtensionProperly() {
197  1 final PathSplitter ps = new PathSplitter("/foo/bar.baz.extension", true);
198  1 assertEquals("foo", ps.next());
199  1 assertEquals("bar.baz", ps.skipTo(1));
200  1 assertEquals("", ps.remaining());
201    }
202    }