Skip to content

Commit

Permalink
Added a few simple test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
kenpaulsen committed Apr 13, 2018
1 parent a98f613 commit 8ef0991
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*
*/
package com.sun.jsftemplating.util.fileStreamer;

import org.junit.Assert;
import org.junit.Test;

/**
* TestCase for <code>ResourceContentSource</code>.
*/
public class ResourceContentSourceTest {

@Test(expected = IllegalArgumentException.class)
public void normalizeDoesNotAccessContextRootParent() {
final String testPath = "../bad/path";
ResourceContentSource.normalize(testPath);
}

@Test(expected = IllegalArgumentException.class)
public void normalizeDoesNotAccessContextRootParentWithLeadingSlash() {
final String testPath = "/../bad/path";
ResourceContentSource.normalize(testPath);
}

@Test(expected = IllegalArgumentException.class)
public void doesNotGoBackTooFar() {
final String testPath = "/path/../../../../too/many/backward";
ResourceContentSource.normalize(testPath);
}

@Test
public void removesExtraSlashesAndBackwardPaths() {
final String testPath = "//OK/path//with/extra/slashes/and/..//in/the/middle/";
final String result = ResourceContentSource.normalize(testPath);
Assert.assertEquals("Wrong result", "OK/path/with/extra/slashes/in/the/middle", result);
}
}

0 comments on commit 8ef0991

Please sign in to comment.