3

I am looking to create a system where a clearly-defined local filesystem folder structure follows a specific pattern. Programmatically or manually violating the pattern should throw an exception.

company/
  |
  ---> building/
           |
           ----> images/
           |        |
           |        --->image.jpg
           |
           |---> issues/
                    |
                    -----> current/
                    |
                    -----> archive/

The pattern above is simplified vs. reality (imagine 7 levels deep and wide).

My thinking is that I can use Junit to make sure the pattern is met. I started writing some custom code with the Paths API in Java 7 over Spring MVC, though it seems like there has to be a faster way that's less error prone. I would want the application to enforce the pattern rather than the OS or an external script. Are there any re-usable classes with that might do this with Junit?

3
  • 1
    I see this is tagged JUnit but I don't see anything specific to JUnit in the question. I am certain there is nothing in JUnit that directly solves this problem.
    – user246
    Commented Apr 17, 2015 at 2:59
  • Which operating system?
    – user246
    Commented Apr 17, 2015 at 3:07
  • Linux, but should that matter? As for Junit, I am looking to run in it a test and given that File IO is fairly common, I was looking for some testing patterns around this. Commented Apr 18, 2015 at 4:01

1 Answer 1

0

You could create a test that checks the following when a file is created:

new File(filePath).exists()

In case its false just throw an exception. If you want that as a JUnit then just wrap it in an assert.

You can read up more on the File Class I used in the example here

Not the answer you're looking for? Browse other questions tagged or ask your own question.