-3

I need to create JUnit test to check if file exists and get from context header and check length, content etc. I found this solutions: JUnit test case to check if file was created but it's only for Unit Test. I use spring framework and I would like use Mockito to simulate created file. Thank you.

Antoine Dubuis
  • 4,974
  • 1
  • 15
  • 29
user3468921
  • 561
  • 2
  • 8
  • 26
  • 1
    ["Can someone help me?" is not a question](http://meta.stackoverflow.com/q/284236). Please [edit] your question to be far more specific about what help you need, so that this doesn't look like a "gimme teh codez" question. – Joe C Jan 28 '18 at 10:39
  • 1
    Write a wrapper for the file system and use Mockito to mock the wrapper. – Dawood ibn Kareem Jan 28 '18 at 10:41

1 Answers1

1

If you want to make asserts on file in a unit test I would recommend you to use Temporary folder:

@Rule
public TemporaryFolder tempFolder = new TemporaryFolder();

@Test
public void testCreateFile() throws IOException{
    File file = tempFolder.newFile("test.txt");
    assertTrue(file.exists());
}

You can find more information on Temporary folder here.

catch23
  • 17,519
  • 42
  • 144
  • 217
Antoine Dubuis
  • 4,974
  • 1
  • 15
  • 29
  • 1
    Nice approach, the thing is that if you use a physical file, your test become an integration one, it is not a unit test anymore – XtianGIS May 09 '18 at 12:53