title: Check file distribution across directories
body: <p><strong>Background</strong></p>
  
  <p>I have an application that is creating a number of subfolders in a fixed directory. Across those directories it is putting a number of files. The number of files is equally distributed across those folders. I have a test that checks for a fixed value across the folders, so n files in each folder.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can i test that, where there are 4 subfolders and 5 messages the distribution of messages across those 4 subfolders is 2 messages in 1 folder and 1 message in the other 3?</p>
  
  <p><strong>Source Code</strong></p>
  
  <pre><code>public boolean checkFileCountInEachFolder(int expectedCount){
      File folder = new File(AppProperties.getInstance().get("path"));
      File[] files = folder.listFiles();
  
      if (files != null) {
          for (int i = 0; i &lt; files.length; i++) {
              File file = files[i];
  
              if (file.isDirectory()) {
                  int fileCount = listFiles(file, new ArrayList&lt;File&gt;()).size();
                  if (fileCount!=expectedCount) {
                      return false;
                  }
              }
          }
      }
  
      return true;
  }
  </code></pre>