From d53449945e02c2d52f76d78f038ffca8585bbc31 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 4 Jul 2012 09:10:10 +0200 Subject: [PATCH] close repository after each unit test --- .../spi/AbstractHgCommandTestBase.java | 24 ++++++++++++++++++- .../repository/spi/HgBlameCommandTest.java | 4 +--- .../scm/repository/spi/HgCatCommandTest.java | 5 ++-- .../scm/repository/spi/HgLogCommandTest.java | 9 ++++--- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/AbstractHgCommandTestBase.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/AbstractHgCommandTestBase.java index fda5e14462..0dda35751e 100644 --- a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/AbstractHgCommandTestBase.java +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/AbstractHgCommandTestBase.java @@ -30,10 +30,12 @@ */ + package sonia.scm.repository.spi; //~--- non-JDK imports -------------------------------------------------------- +import org.junit.After; import org.junit.Assume; import org.junit.Before; @@ -58,6 +60,21 @@ import java.io.IOException; public class AbstractHgCommandTestBase extends ZippedRepositoryTestBase { + /** + * Method description + * + * + * @throws IOException + */ + @After + public void close() throws IOException + { + if (cmdContext != null) + { + cmdContext.close(); + } + } + /** * Method description * @@ -76,7 +93,7 @@ public class AbstractHgCommandTestBase extends ZippedRepositoryTestBase FileSystem fileSystem = mock(FileSystem.class); this.handler = new HgRepositoryHandler(new MemoryStoreFactory(), - fileSystem, new HgContextProvider()); + fileSystem, new HgContextProvider()); this.handler.init(context); // skip tests if hg not in path @@ -85,6 +102,8 @@ public class AbstractHgCommandTestBase extends ZippedRepositoryTestBase System.out.println("WARNING could not find hg, skipping test"); Assume.assumeTrue(false); } + + cmdContext = new HgCommandContext(handler.getConfig(), repositoryDirectory); } //~--- get methods ---------------------------------------------------------- @@ -115,6 +134,9 @@ public class AbstractHgCommandTestBase extends ZippedRepositoryTestBase //~--- fields --------------------------------------------------------------- + /** Field description */ + protected HgCommandContext cmdContext; + /** Field description */ protected HgRepositoryHandler handler; } diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgBlameCommandTest.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgBlameCommandTest.java index 29184c2e35..0dea409589 100644 --- a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgBlameCommandTest.java +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgBlameCommandTest.java @@ -39,7 +39,6 @@ import org.junit.Test; import sonia.scm.repository.BlameLine; import sonia.scm.repository.BlameResult; -import sonia.scm.repository.HgContext; import sonia.scm.repository.RepositoryException; import static org.junit.Assert.*; @@ -139,7 +138,6 @@ public class HgBlameCommandTest extends AbstractHgCommandTestBase */ private BlameCommand createCommand() { - return new HgBlameCommand(new HgCommandContext(handler.getConfig(), - repositoryDirectory), repository); + return new HgBlameCommand(cmdContext, repository); } } diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgCatCommandTest.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgCatCommandTest.java index d8342ca495..c73fa56137 100644 --- a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgCatCommandTest.java +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgCatCommandTest.java @@ -99,15 +99,14 @@ public class HgCatCommandTest extends AbstractHgCommandTestBase * @throws RepositoryException */ private String execute(CatCommandRequest request) - throws IOException, RepositoryException + throws IOException, RepositoryException { String content = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { - new HgCatCommand(new HgCommandContext(handler.getConfig(), - repositoryDirectory), repository).getCatResult(request, baos); + new HgCatCommand(cmdContext, repository).getCatResult(request, baos); } finally { diff --git a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgLogCommandTest.java b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgLogCommandTest.java index d16cef39a8..bae48180ce 100644 --- a/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgLogCommandTest.java +++ b/scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgLogCommandTest.java @@ -95,11 +95,11 @@ public class HgLogCommandTest extends AbstractHgCommandTestBase assertEquals(3, result.getTotal()); assertEquals(3, result.getChangesets().size()); assertEquals("2baab8e80280ef05a9aa76c49c76feca2872afb7", - result.getChangesets().get(0).getId()); + result.getChangesets().get(0).getId()); assertEquals("79b6baf49711ae675568e0698d730b97ef13e84a", - result.getChangesets().get(1).getId()); + result.getChangesets().get(1).getId()); assertEquals("a9bacaf1b7fa0cebfca71fed4e59ed69a6319427", - result.getChangesets().get(2).getId()); + result.getChangesets().get(2).getId()); } /** @@ -235,7 +235,6 @@ public class HgLogCommandTest extends AbstractHgCommandTestBase */ private HgLogCommand createComamnd() { - return new HgLogCommand(new HgCommandContext(handler.getConfig(), - repositoryDirectory), repository); + return new HgLogCommand(cmdContext, repository); } }