0

I wrote some UT with the JUnit Rule TemporaryFolder. In my UT, I mock a service to return this directory like this:

@Rule
public TemporaryFolder folder = new TemporaryFolder();
...
@Test
public void myTest(){
    when(myMock.doSomething()).thenReturn(folder.getRoot());
...

Then in the service, folder is used like this:

IOFileFilter filtreBasique = new NameFileFilter(tagRCPName + ".xml", IOCase.INSENSITIVE);
FileUtils.listFiles(folder, filtreBasique, TrueFileFilter.TRUE);

When I run my UT on my computer, it is all OK, but when I try to run it on Bamboo, I have this error:

java.lang.IllegalArgumentException: Parameter 'directory' is not a directory
at org.apache.commons.io.FileUtils.listFiles(FileUtils.java:358)

I cannot figure out why...

bryce
  • 842
  • 11
  • 35
  • How are you passing `folder` into the class that calls `FileUtils.listFiles`? I assume there are multiple tests being run in Bamboo. Is the class under test part of a context? Is Bamboo reusing this context and thereby getting a previous instance of the class under test? – John B Nov 25 '14 at 12:12
  • `folder` is returned by the mock of my UT. And the class is not a part of a context... `when(myMock.doSomething()).thenReturn(folder.getRoot());` – bryce Nov 25 '14 at 12:33
  • Yeah, I saw that. The point is, how is the mock provided to the class under test? Somehow you are getting `directory` as the folder which is not something `TemporaryFolder` would provide as the root. So somehow your class under test is not using the mock or the mock is not being reset between tests. – John B Nov 25 '14 at 12:40
  • Thanks for the help but I found my mistake and it was nothing really serious... – bryce Nov 25 '14 at 12:57

1 Answers1

1

Finally I found my mistake... It has nothing to do with the Rule JUnit...

It was when I tried to list the files in my directories I had a structure like [TEMP_REPO]\test\test and the separators where hard written. So I replace them by System.getProperty("file.separator") and everything went fine.

Hope this could help someone...

bryce
  • 842
  • 11
  • 35