Created a new class in the TestFile that implements Generated so that the cast later succeeds. 

Patch by: amitmanjhi
Review by: scottb (TBR)



git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5313 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java b/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
index ef955fc..52e6cf2 100644
--- a/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
+++ b/dev/core/test/com/google/gwt/dev/javac/CompilationStateTest.java
@@ -22,6 +22,8 @@
 import com.google.gwt.dev.javac.impl.MockResourceOracle;
 import com.google.gwt.dev.javac.impl.SourceFileCompilationUnit;
 import com.google.gwt.dev.resource.Resource;
+import com.google.gwt.dev.shell.StandardGeneratorContext.Generated;
+import com.google.gwt.dev.util.Util;
 import com.google.gwt.dev.util.log.AbstractTreeLogger;
 import com.google.gwt.dev.util.log.PrintWriterTreeLogger;
 
@@ -41,6 +43,45 @@
  */
 public class CompilationStateTest extends TestCase {
 
+  private class GeneratedSourceFileCompilationUnit extends
+      SourceFileCompilationUnit implements Generated {
+
+    private final boolean modifySource;
+    private String strongHash;
+
+    public GeneratedSourceFileCompilationUnit(Resource sourceFile, boolean modifySource) {
+      super(sourceFile);
+      this.modifySource = modifySource;
+    }
+
+    public void abort() {
+    }
+
+    public void commit() {
+    }
+
+    @Override
+    public String getSource() {
+      String extraChars = "";
+      if (modifySource) {
+        extraChars = "\n";
+      }
+      return super.getSource() + extraChars;
+    }
+
+    public String getStrongHash() {
+      if (strongHash == null) {
+        strongHash = Util.computeStrongName(Util.getBytes(getSource()));
+      }
+      return strongHash;
+    }
+
+    @Override
+    public boolean isGenerated() {
+      return true;
+    }
+  }
+
   static void assertUnitsChecked(Collection<CompilationUnit> units) {
     for (CompilationUnit unit : units) {
       assertSame(State.CHECKED, unit.getState());
@@ -293,12 +334,8 @@
       MockJavaResource... sourceFiles) {
     Set<CompilationUnit> units = new HashSet<CompilationUnit>();
     for (MockJavaResource sourceFile : sourceFiles) {
-      units.add(new SourceFileCompilationUnit(sourceFile) {
-        @Override
-        public boolean isGenerated() {
-          return true;
-        }
-      });
+      // keep the same source
+      units.add(new GeneratedSourceFileCompilationUnit(sourceFile, false));
     }
     return units;
   }
@@ -307,18 +344,8 @@
       MockJavaResource... sourceFiles) {
     Set<CompilationUnit> units = new HashSet<CompilationUnit>();
     for (MockJavaResource sourceFile : sourceFiles) {
-      units.add(new SourceFileCompilationUnit(sourceFile) {
-        /* modified the source */
-        @Override
-        public String getSource() {
-          return super.getSource() + "\n";
-        }
-
-        @Override
-        public boolean isGenerated() {
-          return true;
-        }
-      });
+      // modify the source
+      units.add(new GeneratedSourceFileCompilationUnit(sourceFile, true));
     }
     return units;
   }
@@ -377,8 +404,8 @@
    * <ol>
    * <li>Check graveyardUnits before refresh. assert size is 0.</li>
    * <li>Refresh. assert size is 'graveyardUnitsSize'.</li>
-   * <li>Add generated cups. Confirm that the 'reusedTypes' and
-   * 'numInvalidated' match.</li>
+   * <li>Add generated cups. Confirm that the 'reusedTypes' and 'numInvalidated'
+   * match.</li>
    * </ol>
    * 
    * @param generatedCups generated CompilationUnits to be added.