You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "homberghp (via GitHub)" <gi...@apache.org> on 2025/02/03 14:28:55 UTC

Re: [PR] solves #7044, refactor inner to outer for record [netbeans]

homberghp commented on code in PR #8197:
URL: https://github.com/apache/netbeans/pull/8197#discussion_r1939470549


##########
java/refactoring.java/test/unit/src/org/netbeans/modules/refactoring/java/test/InnerOuterRecordTest.java:
##########
@@ -0,0 +1,635 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.netbeans.modules.refactoring.java.test;
+
+import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.Tree;
+import com.sun.source.util.TreePath;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Name;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+import org.netbeans.api.java.source.CompilationController;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.Task;
+import org.netbeans.api.java.source.TreePathHandle;
+import org.netbeans.modules.refactoring.api.Problem;
+import org.netbeans.modules.refactoring.api.RefactoringSession;
+import org.netbeans.modules.refactoring.java.api.InnerToOuterRefactoring;
+import static org.netbeans.modules.refactoring.java.test.RefactoringTestBase.addAllProblems;
+import org.openide.util.Exceptions;
+
+/**
+ * Test inner to outer refactoring for test.
+ *
+ * In the input files, and the expected outcomes, the indentation does not
+ * really matter as far as the tests are concerned because the indentation is
+ * stripped away before the remaining source lines are compared to the expected
+ * lines.
+ *
+ * @author homberghp {@code <pieter.van.den.hombergh@gmail.com)>}
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class InnerOuterRecordTest extends RefactoringTestBase {
+
+    public InnerOuterRecordTest(String name) {
+        super(name, "16");
+        //ensure we are running on at least 16.
+        try {
+            SourceVersion.valueOf("RELEASE_16"); //NOI18N
+        } catch (IllegalArgumentException ex) {
+            //OK, no RELEASE_16, skip test
+            throw new RuntimeException("need at least Java 16 for record");
+        }
+    }
+
+    // for reference
+    public void test0_259004() throws Exception {
+        String source =
+                """
+            package t;
+            import java.util.function.Consumer;
+            public class A {
+                public static void main(String[] args) {
+                    Consumer<F> c = f -> {};
+                }
+                public static final class F {}
+            }""";
+        String newOuter =
+                """
+            package t;
+            import java.util.function.Consumer;
+            public class A {
+            public static void main(String[] args) {
+                Consumer<F> c = f -> {};
+            }
+            }""";
+        String newInner =
+                """
+            /*
+            * Refactoring License
+            */
+            package t;
+            /**
+             *
+             * @author junit
+             */
+            public final class F {
+            }
+            """;
+        innerOuterSetupAndTest(source, newOuter, newInner);
+    }

Review Comment:
   I agree with less noisy.
   
   As per spec (JLS), the left margin (indentation) is taken from the least indented line in the text block, so it will not affect the tests.
   In the tests I have written, I specifically discarded the indentation, to make the test independent of any formatting settings. This is on purpose.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists