/*
 * Copyright 2000-2014 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.idea.maven.execution;

import com.intellij.execution.configurations.JavaParameters;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.idea.maven.MavenImportingTestCase;

import static java.util.Arrays.asList;

public class MavenJUnitPatcherTest extends MavenImportingTestCase {
  public void testArgList() throws Exception {
    VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" +
                                           "<artifactId>m1</artifactId>" +
                                           "<version>1</version>" +
                                           "<dependencies>" +
                                           "  <dependency>" +
                                           "    <groupId>test</groupId>" +
                                           "    <artifactId>m2</artifactId>" +
                                           "    <version>1</version>" +
                                           "  </dependency>" +
                                           "</dependencies>" +
                                           "<build><plugins>" +
                                           "  <plugin>" +
                                           "    <groupId>org.apache.maven.plugins</groupId>" +
                                           "    <artifactId>maven-surefire-plugin</artifactId>" +
                                           "    <version>2.16</version>" +
                                           "    <configuration>" +
                                           "      <argLine>-Xmx2048M -XX:MaxPermSize=512M \"-Dargs=can have spaces\"</argLine>" +
                                           "    </configuration>" +
                                           "  </plugin>" +
                                           "</plugins></build>");

    importProjects(m1);
    Module module = getModule("m1");

    MavenJUnitPatcher mavenJUnitPatcher = new MavenJUnitPatcher();
    JavaParameters javaParameters = new JavaParameters();
    mavenJUnitPatcher.patchJavaParameters(module, javaParameters);
    assertEquals(asList("-Xmx2048M", "-XX:MaxPermSize=512M", "-Dargs=can have spaces"),
                 javaParameters.getVMParametersList().getList());
  }
}

@@ -843,16 +843,78 @@
 estCase;
+%0Aimport org.jetbrains.idea.maven.project.MavenProjectSettings;
 %0A%0Aimport
@@ -1015,16 +1015,404 @@
 tCase %7B%0A
+%0A  @Override%0A  protected void setUp() throws Exception %7B%0A    super.setUp();%0A    MavenProjectSettings.getInstance(myProject).getTestRunningSettings().setPassArgLine(true);%0A    MavenProjectSettings.getInstance(myProject).getTestRunningSettings().setPassEnvironmentVariables(true);%0A    MavenProjectSettings.getInstance(myProject).getTestRunningSettings().setPassSystemProperties(true);%0A  %7D%0A%0A
   public

Fix maven test