gt:         buf = new StringBuffer();
context: /**
   * ***************************************************************************** Copyright (c) 2000,
   * 2012 IBM Corporation and others. All rights reserved. This program and the accompanying materials
   * are made available under the terms of the Eclipse Public License v1.0 which accompanies this
   * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
   *
   * <p>Contributors: IBM Corporation - initial API and implementation
   * *****************************************************************************
   */
  package org.eclipse.che.plugin.java.server.jdt.quickfix;
  
  import static org.junit.Assert.assertTrue;
  
  import java.util.ArrayList;
  import java.util.Hashtable;
  import org.eclipse.che.plugin.java.server.jdt.testplugin.JavaProjectHelper;
  import org.eclipse.che.plugin.java.server.jdt.testplugin.ProjectTestSetup;
  import org.eclipse.che.plugin.java.server.jdt.testplugin.TestOptions;
  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.JavaCore;
  import org.eclipse.jdt.core.dom.CompilationUnit;
  import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
  import org.eclipse.jdt.internal.ui.JavaPlugin;
  import org.eclipse.jdt.ui.PreferenceConstants;
  import org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal;
  import org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal;
  import org.eclipse.jface.preference.IPreferenceStore;
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
  
  public class ReturnTypeQuickFixTest extends QuickFixTest {
  
    private static final Class THIS = ReturnTypeQuickFixTest.class;
  
    private IJavaProject fJProject1;
    private IPackageFragmentRoot fSourceFolder;
  
    public ReturnTypeQuickFixTest() {
      super(new ProjectTestSetup());
    }
    //
    //	public static Test suite() {
    //		return setUpTest(new TestSuite(THIS));
    //	}
    //
    //	public static Test setUpTest(Test test) {
    //		return new ProjectTestSetup(test);
    //	}
  
    @Before
    public void setUp() throws Exception {
      super.setUp();
      Hashtable options = TestOptions.getDefaultOptions();
      options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
      options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
      options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE);
      JavaCore.setOptions(options);
  
      IPreferenceStore store = JavaPlugin.getDefault().getPreferenceStore();
      store.setValue(PreferenceConstants.CODEGEN_ADD_COMMENTS, false);
  
      fJProject1 = ProjectTestSetup.getProject();
  
      fSourceFolder = JavaProjectHelper.addSourceContainer(fJProject1, "src");
    }
  
    @After
    public void tearDown() throws Exception {
      super.tearDown();
      JavaProjectHelper.clear(fJProject1, ProjectTestSetup.getDefaultClasspath());
    }
  
    @Test
    public void testReturnTypeMissingWithSimpleType() throws Exception {
      IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
      StringBuffer buf = new StringBuffer();
      buf.append("package test1;\n");
      buf.append("import java.util.Vector;\n");
      buf.append("public class E {\n");
      buf.append("    public foo() {\n");
      buf.append("        return (new Vector()).elements();\n");
      buf.append("    }\n");
      buf.append("}\n");
      ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
  
      CompilationUnit astRoot = getASTRoot(cu);
      ArrayList proposals = collectCorrections(cu, astRoot);
      assertNumberOfProposals(proposals, 2);
      assertCorrectLabels(proposals);
  
      boolean addReturnType = true, doRename = true;
  
      for (int i = 0; i < proposals.size(); i++) {
        Object elem = proposals.get(i);
        if (elem instanceof ASTRewriteCorrectionProposal) {
          ASTRewriteCorrectionProposal proposal = (ASTRewriteCorrectionProposal) elem;
          assertTrue("duplicated entries", addReturnType);
          addReturnType = false;
  
          String preview = getPreviewContent(proposal);
  
          buf = new StringBuffer();
          buf.append("package test1;\n");
          buf.append("import java.util.Enumeration;\n");
          buf.append("import java.util.Vector;\n");
          buf.append("public class E {\n");
          buf.append("    public Enumeration foo() {\n");
          buf.append("        return (new Vector()).elements();\n");
          buf.append("    }\n");
          buf.append("}\n");
          assertEqualString(preview, buf.toString());
        } else {
          assertTrue("duplicated entries", doRename);
          doRename = false;
  
          CUCorrectionProposal proposal = (CUCorrectionProposal) elem;
          String preview = getPreviewContent(proposal);
          buf = new StringBuffer();
          buf.append("package test1;\n");
          buf.append("import java.util.Vector;\n");
          buf.append("public class E {\n");
          buf.append("    public E() {\n");
          buf.append("        return (new Vector()).elements();\n");
          buf.append("    }\n");
          buf.append("}\n");
          assertEqualString(preview, buf.toString());
        }
      }
    }
  
    @Test
    public void testReturnTypeMissingWithVoid() throws Exception {
      IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
      StringBuffer buf = new StringBuffer();
      buf.append("package test1;\n");
      buf.append("public class E {\n");
      buf.append("    public foo() {\n");
      buf.append("        //do nothing\n");
      buf.append("    }\n");
      buf.append("}\n");
      ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
  
      CompilationUnit astRoot = getASTRoot(cu);
      ArrayList proposals = collectCorrections(cu, astRoot);
      assertNumberOfProposals(proposals, 2);
      assertCorrectLabels(proposals);
  
      boolean addReturnType = true, doRename = true;
  
      for (int i = 0; i < proposals.size(); i++) {
        Object elem = proposals.get(i);
        if (elem instanceof ASTRewriteCorrectionProposal) {
          ASTRewriteCorrectionProposal proposal = (ASTRewriteCorrectionProposal) elem;
          assertTrue("duplicated entries", addReturnType);
          addReturnType = false;
  
          String preview = getPreviewContent(proposal);
  
          buf = new StringBuffer();
          buf.append("package test1;\n");
          buf.append("public class E {\n");
          buf.append("    public void foo() {\n");
          buf.append("        //do nothing\n");
          buf.append("    }\n");
          buf.append("}\n");
          assertEqualString(preview, buf.toString());
        } else {
          assertTrue("duplicated entries", doRename);
          doRename = false;
  
          CUCorrectionProposal proposal = (CUCorrectionProposal) elem;
          String preview = getPreviewContent(proposal);
          buf = new StringBuffer();
          buf.append("package test1;\n");
          buf.append("public class E {\n");
          buf.append("    public E() {\n");
          buf.append("        //do nothing\n");
          buf.append("    }\n");
          buf.append("}\n");
          assertEqualString(preview, buf.toString());
        }
      }
    }
  
    @Test
    public void testReturnTypeMissing() throws Exception {
      IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
      StringBuffer buf = new StringBuffer();
      buf.append("package test1;\n");
      buf.append("public interface E {\n");
      buf.append("    public foo();\n");
      buf.append("}\n");
      ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
  
      CompilationUnit astRoot = getASTRoot(cu);
      ArrayList proposals = collectCorrections(cu, astRoot);
      assertNumberOfProposals(proposals, 1);
      assertCorrectLabels(proposals);
  
      ASTRewriteCorrectionProposal proposal = (ASTRewriteCorrectionProposal) proposals.get(0);
      String preview1 = getPreviewContent(proposal);
  
      buf = new StringBuffer();
      buf.append("package test1;\n");
      buf.append("public interface E {\n");
      buf.append("    public void foo();\n");
      buf.append("}\n");
      String expected1 = buf.toString();
  
      assertEqualStringsIgnoreOrder(new String[] {preview1}, new String[] {expected1});
    }
  
    @Test
    public void testReturnTypeMissingWithVoid2() throws Exception {
      IPackageFragment pack1 = fSourceFolder.createPackageFragment("test1", false, null);
      StringBuffer buf = new StringBuffer();
      buf.append("package test1;\n");
      buf.append("public class E {\n");
      buf.append("    public foo() {\n");
      buf.append("        if (true) {\n");
      buf.append("           return;\n");
      buf.append("        }\n");
      buf.append("        return;\n");
      buf.append("    }\n");
      buf.append("}\n");
      ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
  
      CompilationUnit astRoot = getASTRoot(cu);
      ArrayList proposals = collectCorrections(cu, astRoot);
      assertNumberOfProposals(proposals, 2);
      assertCorrectLabels(proposals);
  
      boolean addReturnType = true, doRename = true;
  
      for (int i = 0; i < proposals.size(); i++) {
        Object elem = proposals.get(i);
        if (elem instanceof ASTRewriteCorrectionProposal) {
          ASTRewriteCorrectionProposal proposal = (ASTRewriteCorrectionProposal) elem;
          assertTrue("duplicated entries", addReturnType);
          addReturnType = false;
  
          String preview = getPreviewContent(proposal);
  
  