title: mock item in cache directory for unit tests
body: <p>I'm currently writing unit tests that involve files in the cache directory. The problem that is happening is when the app is launched for the first time the cache related tests fail with errors like:</p>
  
  <blockquote>
    <p>The file “5b063e275d506f65ebf1b02d926f19a4” couldn’t be opened because
    there is no such file.</p>
  </blockquote>
  
  <p>I believe the reason for this is because since the app is being opened for first time there is nothing in the cache directory. Is there a way to insert files in the cache directory in the unit test itself so this error isn't thrown?</p>
  
  <p>This is a sample unit test:</p>
  
  <pre><code>  internal func filePathForFileName(name: String) -&gt; String {
          let cyptoName = name.md5()
          return getCacheFolderPath() + "/" + (cyptoName ?? "")
      }
  
      internal func getCacheFolderPath() -&gt; String {
          var folderPath = ""
          guard let path = self.urls(for:.cachesDirectory , in: .userDomainMask).last?.path else {
              return folderPath }
          folderPath = path + "/NetworkCache"
          if !self.fileExists(atPath: folderPath) {
              do {
                try  self.createDirectory(atPath: folderPath, withIntermediateDirectories: false, attributes: nil)
              }
              catch {
                  print(error.localizedDescription)
              }
      }
          return folderPath
      }
  }
  
    func saveData(data: Data, forFileName fileName: String, completionHandler: @escaping (URL?)-&gt;()) {
          let url = URL(fileURLWithPath: self.filePathForFileName(name: fileName))
          print("saveData:\(url)")
          do {
              try  data.write(to: url, options: .atomic)
                completionHandler(url)
          } catch  {
              print(error.localizedDescription)
              completionHandler(nil)
  
          }
      }
  
   let filePath = "fileName"
  
      func test_saveData(){
  
          let promise = expectation(description: "Completion Hander invoked")
  
          var isSaved: Bool?
  
          let path =  self.sut!.filePathForFileName(name: self.filePath)
  
          sut?.saveData(data: mockData!, forFileName: filePath, completionHandler: {_ in
  
              let fileManager = MockFileManager.default
  
              if fileManager.fileExists(atPath: path) {
                  isSaved = true
                  print("FILE AVAILABLE")
  
              } else {
                  isSaved = false
                  print("FILE NOT AVAILABLE")
              }
  
              promise.fulfill()
  
          })
  
          wait(for: [promise], timeout: 10, enforceOrder: true)
          XCTAssertTrue(isSaved!)
      }
  </code></pre>