Skip to content

Commit

Permalink
Merge pull request #1 from kenpaulsen/pr-49-suggestions
Browse files Browse the repository at this point in the history
Added a few simple test cases.
  • Loading branch information
jayasheelankumar authored Apr 18, 2018
2 parents cc5b481 + 8ef0991 commit 6069d03
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 6069d03

Please sign in to comment.