/*
 * Copyright 2000-2013 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 org.jetbrains.plugins.gradle.service.project;

import com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException;
import org.gradle.internal.exceptions.LocationAwareException;
import org.jetbrains.annotations.NotNull;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author Vladislav.Soroka
 */
public class BaseProjectImportErrorHandlerTest {
  private BaseProjectImportErrorHandler myErrorHandler;
  private String myProjectPath;

  @Before
  public void setUp() {
    myErrorHandler = new BaseProjectImportErrorHandler();
    myProjectPath = "basic";
  }

  @Test
  public void testGetUserFriendlyError() {
    String causeMsg = "failed to find target current";
    RuntimeException rootCause = new IllegalStateException(causeMsg);
    String locationMsg = "Build file '~/project/build.gradle' line: 86";

    RuntimeException locationError = new RuntimeException(locationMsg, rootCause) {
      @NotNull
      @Override
      public String toString() {
        return LocationAwareException.class.getName() + ": " + super.toString();
      }
    };

    Throwable error = new Throwable(locationError);

    RuntimeException realCause = myErrorHandler.getUserFriendlyError(null, error, myProjectPath, null);
    assertTrue(realCause instanceof LocationAwareExternalSystemException);
    LocationAwareExternalSystemException locationAwareExternalSystemException = (LocationAwareExternalSystemException)realCause;
    assertEquals("~/project/build.gradle", locationAwareExternalSystemException.getFilePath());
    assertEquals(Integer.valueOf(-1), locationAwareExternalSystemException.getColumn());
    assertEquals(Integer.valueOf(86), locationAwareExternalSystemException.getLine());
  }

  @Test
  public void testGetUserFriendlyErrorWithClassNotFoundException() {
    String causeMsg = "com.mypackage.MyImaginaryClass";
    ClassNotFoundException rootCause = new ClassNotFoundException(causeMsg);
    Throwable error = new Throwable(rootCause);
    RuntimeException realCause = myErrorHandler.getUserFriendlyError(null, error, myProjectPath, null);
    assertTrue(realCause.getMessage().contains("Unable to load class 'com.mypackage.MyImaginaryClass'."));
  }
}

@@ -728,32 +728,85 @@
 ystemException;%0A
+import com.intellij.testFramework.LightIdeaTestCase;%0A
 import org.gradl
@@ -896,145 +896,8 @@
 ull;
-%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;
 %0A%0A/*
@@ -977,16 +977,42 @@
 lerTest 
+extends LightIdeaTestCase 
 %7B%0A  priv
@@ -1101,13 +1101,15 @@
 %0A  @
-Befor
+Overrid
 e%0A  
@@ -1128,17 +1128,53 @@
 setUp() 
-%7B
+throws Exception %7B%0A    super.setUp();
 %0A    myE
@@ -1254,32 +1254,24 @@
 asic%22;%0A  %7D%0A%0A
-  @Test%0A
   public voi
@@ -2387,16 +2387,8 @@
  %7D%0A%0A
-  @Test%0A
   pu

test fix