blob: ecd98b8a7b6588dbfc472c395f26f1408417862f [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.ui.tests.quickfix;
import java.util.ArrayList;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.eclipse.jdt.testplugin.JavaProjectHelper;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.internal.corext.util.Messages;
import org.eclipse.jdt.ui.tests.core.rules.Java14ProjectTestSetup;
import org.eclipse.jdt.ui.tests.core.rules.ProjectTestSetup;
import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal;
import org.eclipse.jdt.internal.ui.text.correction.CorrectionMessages;
@RunWith(JUnit4.class)
public class QuickFixTest15 extends QuickFixTest {
@Rule
public ProjectTestSetup projectsetup= new Java14ProjectTestSetup(true);
private IJavaProject fJProject;
private IPackageFragmentRoot fSourceFolder;
@After
public void tearDown() throws Exception {
if (fJProject != null) {
JavaProjectHelper.delete(fJProject);
}
}
@Test
public void testTextBlockGetNeedHigherComplianceProposal() throws Exception {
fJProject= JavaProjectHelper.createJavaProject("TestProject1", "bin");
fJProject.setRawClasspath(projectsetup.getDefaultClasspath(), null);
JavaProjectHelper.set14CompilerOptions(fJProject, false);
fSourceFolder= JavaProjectHelper.addSourceContainer(fJProject, "src");
IPackageFragment def= fSourceFolder.createPackageFragment("", false, null);
def.createCompilationUnit(QuickFixTest14.MODULE_INFO_FILE, QuickFixTest14.MODULE_INFO_FILE_CONTENT, false, null);
IPackageFragment pack= fSourceFolder.createPackageFragment("test", false, null);
String test= ""
+ "package test;\n"
+ "public class Cls1 {\n"
+ " public static void main(String[] args) {\n"
+ " String str= \"\"\"\n"
+ " Hello\n"
+ " World\n"
+ " \"\"\";\n"
+ " System.out.println(str);\n"
+ " }\n"
+ "}\n";
ICompilationUnit cu= pack.createCompilationUnit("Cls1.java", test, false, null);
CompilationUnit astRoot= getASTRoot(cu);
ArrayList<IJavaCompletionProposal> proposals= collectCorrections(cu, astRoot, 1, null);
assertNumberOfProposals(proposals, 1);
String label= Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_change_project_compliance_description, "15");
assertProposalExists(proposals, label);
}
}