Skip to content
Snippets Groups Projects
Commit 3d6d4f21 authored by buczekp's avatar buczekp
Browse files

[LMS-1586] refactored common code in test

SVN: 20981
parent 8c133ffd
No related branches found
No related tags found
No related merge requests found
...@@ -191,15 +191,8 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT ...@@ -191,15 +191,8 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT
public void testGetRootNode() public void testGetRootNode()
{ {
final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); 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(); IHierarchicalContentNode root1 = rootContent.getRootNode();
assertSame(rootDir, root1.getFile()); assertSame(rootDir, root1.getFile());
IHierarchicalContentNode root2 = rootContent.getRootNode(); IHierarchicalContentNode root2 = rootContent.getRootNode();
...@@ -212,15 +205,8 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT ...@@ -212,15 +205,8 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT
public void testGetNodeWithBlankPath() public void testGetNodeWithBlankPath()
{ {
final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); 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 rootNode = rootContent.getRootNode();
IHierarchicalContentNode nullNode = rootContent.getNode(null); IHierarchicalContentNode nullNode = rootContent.getNode(null);
IHierarchicalContentNode emptyNode = rootContent.getNode(""); IHierarchicalContentNode emptyNode = rootContent.getNode("");
...@@ -272,16 +258,7 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT ...@@ -272,16 +258,7 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT
createHDF5Container(subContainerDir, subDir); createHDF5Container(subContainerDir, subDir);
final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir);
prepareCreateRootNode(rootContent);
// 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)));
}
});
final List<File> subDirFiles = Arrays.asList(subFile1, subFile2, subFile3, subSubFile); final List<File> subDirFiles = Arrays.asList(subFile1, subFile2, subFile3, subSubFile);
for (File subDirFile : subDirFiles) for (File subDirFile : subDirFiles)
...@@ -330,15 +307,7 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT ...@@ -330,15 +307,7 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT
public void testListMatchingNodesWithRelativePathPattern() public void testListMatchingNodesWithRelativePathPattern()
{ {
final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir);
prepareCreateRootNode(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)));
}
});
// nothing matches // nothing matches
assertEquals(0, rootContent.listMatchingNodes(".*non-mathching-pattern.*").size()); assertEquals(0, rootContent.listMatchingNodes(".*non-mathching-pattern.*").size());
...@@ -388,14 +357,7 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT ...@@ -388,14 +357,7 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT
public void testListMatchingNodesWithStartingPath() public void testListMatchingNodesWithStartingPath()
{ {
final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir);
prepareCreateNode(rootContent, subDir);
context.checking(new Expectations()
{
{
one(hierarchicalContentFactory).asHierarchicalContentNode(rootContent, subDir);
will(returnValue(createDummyFileBasedNode(rootDir, subDir)));
}
});
List<IHierarchicalContentNode> matchingNodes = List<IHierarchicalContentNode> matchingNodes =
rootContent.listMatchingNodes("subDir", ".*[fF]ile.*"); rootContent.listMatchingNodes("subDir", ".*[fF]ile.*");
...@@ -419,15 +381,6 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT ...@@ -419,15 +381,6 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT
final DefaultFileBasedHierarchicalContent rootContent = createContent(rootDir); 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 relativePath = FileUtilities.getRelativeFile(rootDir, subSubDir);
final String containerRelativePath = final String containerRelativePath =
relativePath.replace(subDir.getName(), subContainerDir.getName()); relativePath.replace(subDir.getName(), subContainerDir.getName());
...@@ -457,6 +410,31 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT ...@@ -457,6 +410,31 @@ public class DefaultFileBasedHierarchicalContentTest extends AbstractFileSystemT
context.assertIsSatisfied(); 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 String METHOD_NOT_IMPLEMENTED = "method not implemented in dummy node";
private static void checkNodeMatchesFile(IHierarchicalContentNode node, File expectedFile) private static void checkNodeMatchesFile(IHierarchicalContentNode node, File expectedFile)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment