// Copyright 2013 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.enterprise.adaptor;

import java.io.*;

/** Mock File for testing file-related code paths. */
class MockFile extends File {
  private String fileContents = "";
  private long lastModified;
  private boolean exists = true;

  public MockFile(String name) {
    super(name);
  }

  public Reader createReader() {
    return new StringReader(fileContents);
  }

  public void setFileContents(String fileContents) {
    this.fileContents = fileContents;
  }

  @Override
  public long lastModified() {
    return lastModified;
  }

  @Override
  public boolean setLastModified(long time) {
    this.lastModified = time;
    return true;
  }

  @Override
  public boolean exists() {
    return exists;
  }

  public void setExists(boolean exists) {
    this.exists = exists;
  }

  @Override
  public boolean isFile() {
    return true;
  }
}

@@ -930,24 +930,111 @@
 eReader() %7B%0A
+    if (!exists) %7B%0A      throw new IllegalStateException(%22File does not exist%22);%0A    %7D%0A
     return n
@@ -1064,16 +1064,16 @@
 tents);%0A
-
   %7D%0A%0A  p
@@ -1204,24 +1204,65 @@
 odified() %7B%0A
+    if (!exists) %7B%0A      return 0;%0A    %7D%0A
     return l
@@ -1374,28 +1374,30 @@
 %0A    return 
-true
+exists
 ;%0A  %7D%0A%0A  @Ov
@@ -1576,19 +1576,81 @@
     
-return true
+// This only mocks files, not directories and the like.%0A    return exists
 ;%0A  

Improve MockFile to be more internally consistent