From 3d6d4f2146569cadaffcd1d1be36b98a9b46f571 Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Tue, 19 Apr 2011 12:37:53 +0000 Subject: [PATCH] [LMS-1586] refactored common code in test SVN: 20981 --- ...faultFileBasedHierarchicalContentTest.java | 82 +++++++------------ 1 file changed, 30 insertions(+), 52 deletions(-) diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/io/DefaultFileBasedHierarchicalContentTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/io/DefaultFileBasedHierarchicalContentTest.java index 8b155ec53d0..f594e17c0e5 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/io/DefaultFileBasedHierarchicalContentTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/io/DefaultFileBasedHierarchicalContentTest.java @@ -191,15 +191,8 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT public void testGetRootNode() { final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); + prepareCreateRootNode(rootContent); - context.checking(new Expectations() - { - { - // root node should be created only once even though we access it twice - one(hierarchicalContentFactory).asHierarchicalContentNode(rootContent, rootDir); - will(returnValue(createDummyFileBasedRootNode(rootDir))); - } - }); IHierarchicalContentNode root1 = rootContent.getRootNode(); assertSame(rootDir, root1.getFile()); IHierarchicalContentNode root2 = rootContent.getRootNode(); @@ -212,15 +205,8 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT public void testGetNodeWithBlankPath() { final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); + prepareCreateRootNode(rootContent); - context.checking(new Expectations() - { - { - // root node should be created only once even though we access it twice - one(hierarchicalContentFactory).asHierarchicalContentNode(rootContent, rootDir); - will(returnValue(createDummyFileBasedRootNode(rootDir))); - } - }); IHierarchicalContentNode rootNode = rootContent.getRootNode(); IHierarchicalContentNode nullNode = rootContent.getNode(null); IHierarchicalContentNode emptyNode = rootContent.getNode(""); @@ -272,16 +258,7 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT createHDF5Container(subContainerDir, subDir); final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); - - // access to root dir is needed to get relative path of a file inside container - context.checking(new Expectations() - { - { - // root node should be created only once even though we access it many times - one(hierarchicalContentFactory).asHierarchicalContentNode(rootContent, rootDir); - will(returnValue(createDummyFileBasedRootNode(rootDir))); - } - }); + prepareCreateRootNode(rootContent); final List<File> subDirFiles = Arrays.asList(subFile1, subFile2, subFile3, subSubFile); for (File subDirFile : subDirFiles) @@ -330,15 +307,7 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT public void testListMatchingNodesWithRelativePathPattern() { final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); - - context.checking(new Expectations() - { - { - // root node should be created only once even though we access it many times - one(hierarchicalContentFactory).asHierarchicalContentNode(rootContent, rootDir); - will(returnValue(createDummyFileBasedRootNode(rootDir))); - } - }); + prepareCreateRootNode(rootContent); // nothing matches assertEquals(0, rootContent.listMatchingNodes(".*non-mathching-pattern.*").size()); @@ -388,14 +357,7 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT public void testListMatchingNodesWithStartingPath() { final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); - - context.checking(new Expectations() - { - { - one(hierarchicalContentFactory).asHierarchicalContentNode(rootContent, subDir); - will(returnValue(createDummyFileBasedNode(rootDir, subDir))); - } - }); + prepareCreateNode(rootContent, subDir); List<IHierarchicalContentNode> matchingNodes = rootContent.listMatchingNodes("subDir", ".*[fF]ile.*"); @@ -419,15 +381,6 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); - context.checking(new Expectations() - { - { - // root node should be created only once even though we access it many times - one(hierarchicalContentFactory).asHierarchicalContentNode(rootContent, rootDir); - will(returnValue(createDummyFileBasedRootNode(rootDir))); - } - }); - final String relativePath = FileUtilities.getRelativeFile(rootDir, subSubDir); final String containerRelativePath = relativePath.replace(subDir.getName(), subContainerDir.getName()); @@ -457,6 +410,31 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT context.assertIsSatisfied(); } + private void prepareCreateNode(final DefaultFileBasedHierarchicalContent rootContent, + final File file) + { + context.checking(new Expectations() + { + { + // root node should be created only once even though we access it many times + one(hierarchicalContentFactory).asHierarchicalContentNode(rootContent, file); + will(returnValue(createDummyFileBasedNode(rootDir, file))); + } + }); + } + + private void prepareCreateRootNode(final DefaultFileBasedHierarchicalContent rootContent) + { + context.checking(new Expectations() + { + { + // root node should be created only once even though we access it many times + one(hierarchicalContentFactory).asHierarchicalContentNode(rootContent, rootDir); + will(returnValue(createDummyFileBasedRootNode(rootDir))); + } + }); + } + private static String METHOD_NOT_IMPLEMENTED = "method not implemented in dummy node"; private static void checkNodeMatchesFile(IHierarchicalContentNode node, File expectedFile) -- GitLab