/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * 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.intellij.testFramework;

import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

public abstract class HighlightTestInfo implements Disposable {
  @NotNull protected final String[] filePaths;
  protected boolean checkWarnings;
  protected boolean checkInfos;
  protected boolean checkSymbolNames;
  protected boolean checkWeakWarnings;
  protected String projectRoot;
  private boolean tested;
  private final String myPlace;

  public HighlightTestInfo(@NotNull Disposable parentDisposable, @NonNls @NotNull String... filePaths) {
    this.filePaths = filePaths;
    // disposer here for catching the case of not calling test()
    Disposer.register(parentDisposable, this);
    myPlace = parentDisposable.toString();
  }
  public HighlightTestInfo checkWarnings() { checkWarnings = true; return this; }
  public HighlightTestInfo checkWeakWarnings() { checkWeakWarnings = true; return this; }
  public HighlightTestInfo checkInfos() { checkInfos = true; return this; }
  public HighlightTestInfo checkSymbolNames() { checkSymbolNames = true; return this; }
  public HighlightTestInfo projectRoot(@NonNls @NotNull String root) { projectRoot = root; return this; }

  public HighlightTestInfo test() throws Exception {
    doTest();
    tested = true;
    Disposer.dispose(this);
    return this;
  }

  @Override
  public void dispose() {
    assert tested : "You must call HighlightTestInfo.test() in " + myPlace;
  }

  protected abstract HighlightTestInfo doTest() throws Exception;
}

@@ -17,17 +17,17 @@
 2000-201
-1
+2
  JetBrai
@@ -1440,16 +1440,17 @@
 ();%0A  %7D%0A
+%0A
   public
@@ -1937,16 +1937,28 @@
 ption %7B%0A
+    try %7B%0A  
     doTe
@@ -1963,16 +1963,57 @@
 Test();%0A
+      return this;%0A    %7D%0A    finally %7B%0A  
     test
@@ -2023,16 +2023,18 @@
 = true;%0A
+  
     Disp
@@ -2057,28 +2057,17 @@
 s);%0A    
-return this;
+%7D
 %0A  %7D%0A%0A  

Fix chained assertion