Skip to content

Commit

Permalink
Issue 11303 fixing junit logic (#11449)
Browse files Browse the repository at this point in the history
* #11303: Fixing JUnit logic to preserve original value

* #11303: Fixing Junit logic

* #11303: Verify original root is successfully reestablished
  • Loading branch information
danlaguna authored and dsilvam committed May 1, 2017
1 parent dbd68ad commit 6f6acfd
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.mockito.Mockito;

import static org.hamcrest.MatcherAssert.assertThat;

Expand All @@ -22,8 +21,6 @@ public class VelocityUtilTest {
@BeforeClass
public static void prepare() throws Exception {
IntegrationTestInitService.getInstance().init();
Mockito.when(Config.CONTEXT.getRealPath("/WEB-INF/velocity"))
.thenReturn(Config.getStringProperty("VELOCITY_ROOT", "/WEB-INF/velocity"));
}

/**
Expand All @@ -42,17 +39,19 @@ public void test01DefaultVelocityPath() throws Exception {
*/
@Test
public void test02CustomVelocityPath() throws Exception {
String velocityPath = Config.getStringProperty("VELOCITY_ROOT", "/WEB-INF/velocity");
velocityPath = velocityPath.replace("/WEB-INF/velocity", "/WEB-INF/customvelocity");
Config.setProperty("VELOCITY_ROOT", velocityPath);
String originalVelocityPath = Config.getStringProperty("VELOCITY_ROOT", "/WEB-INF/velocity");
String newVelocityPath = "/WEB-INF/customVelocity";
Config.setProperty("VELOCITY_ROOT", newVelocityPath);

String customVelocityPath = VelocityUtil.getVelocityRootPath();

Assert.assertNotNull(customVelocityPath);
assertThat("Path ends with /WEB-INF/customvelocity", customVelocityPath.endsWith("/WEB-INF/customvelocity"));
assertThat("Path ends with /WEB-INF/customVelocity", customVelocityPath.endsWith("/WEB-INF/customVelocity"));

// restore the default value (used on other tests)
Config.setProperty("VELOCITY_ROOT", "/WEB-INF/velocity");
Config.setProperty("VELOCITY_ROOT", originalVelocityPath);
String velocityRoot = Config.getStringProperty("VELOCITY_ROOT");
assertThat("Path velocity root has been successfully restored", originalVelocityPath.equals(velocityRoot));
}

}

0 comments on commit 6f6acfd

Please sign in to comment.