1313 *******************************************************************************/
1414package org .eclipse .jdt .text .tests .folding ;
1515
16+ import static org .junit .Assume .assumeTrue ;
17+
1618import java .util .List ;
1719
1820import org .junit .After ;
1921import org .junit .Before ;
2022import org .junit .Rule ;
2123import org .junit .Test ;
24+ import org .junit .runner .RunWith ;
25+ import org .junit .runners .Parameterized ;
26+ import org .junit .runners .Parameterized .Parameter ;
27+ import org .junit .runners .Parameterized .Parameters ;
2228
2329import org .eclipse .jdt .testplugin .JavaProjectHelper ;
2430
3743
3844import org .eclipse .jdt .internal .ui .JavaPlugin ;
3945
46+ @ RunWith (Parameterized .class )
4047public class FoldingTest {
4148 @ Rule
4249 public ProjectTestSetup projectSetup = new ProjectTestSetup ();
@@ -47,6 +54,14 @@ public class FoldingTest {
4754
4855 private IPackageFragment packageFragment ;
4956
57+ @ Parameters (name = "New folding active: {0}" )
58+ public static Object [] data () {
59+ return new Object [] { true , false };
60+ }
61+
62+ @ Parameter
63+ public boolean newFoldingActive ;
64+
5065 @ Before
5166 public void setUp () throws CoreException {
5267 jProject = projectSetup .getProject ();
@@ -56,12 +71,13 @@ public void setUp() throws CoreException {
5671 }
5772 packageFragment = sourceFolder .createPackageFragment ("org.example.test" , false , null );
5873 IPreferenceStore store = JavaPlugin .getDefault ().getPreferenceStore ();
59- store .setValue (PreferenceConstants .EDITOR_NEW_FOLDING_ENABLED , true );
60- }
74+ store .setValue (PreferenceConstants .EDITOR_NEW_FOLDING_ENABLED , newFoldingActive );
75+ }
6176
6277 @ After
6378 public void tearDown () throws CoreException {
6479 JavaProjectHelper .delete (jProject );
80+ JavaPlugin .getDefault ().getPreferenceStore ().setToDefault (PreferenceConstants .EDITOR_NEW_FOLDING_ENABLED );
6581 }
6682
6783 @ Test
@@ -242,15 +258,17 @@ void b() { //here should be an annotation
242258 }
243259 }
244260 """ ;
245- FoldingTestUtils .assertCodeHasRegions (packageFragment , "TestFolding.java" , str , 6 );
261+ FoldingTestUtils .assertCodeHasRegions (packageFragment , "TestFolding.java" , str , newFoldingActive ? 6 : 5 );
246262
247263 List <IRegion > regions = FoldingTestUtils .getProjectionRangesOfFile (packageFragment , "TestFolding.java" , str );
248264 FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 1 , 3 ); // 1. Javadoc
249265 FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 4 , 6 ); // 2. Javadoc
250266 FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 7 , 9 ); // 3. Javadoc
251267 FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 12 , 14 ); // 4. Javadoc
252268 FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 15 , 19 ); // Methode b()
253- FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 16 , 18 ); // 5. Javadoc
269+ if (newFoldingActive ) {
270+ FoldingTestUtils .assertContainsRegionUsingStartAndEndLine (regions , str , 16 , 18 ); // 5. Javadoc
271+ }
254272 }
255273
256274 @ Test
@@ -286,6 +304,7 @@ void a() {
286304
287305 @ Test
288306 public void testIfStatementFolding () throws Exception {
307+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
289308 String str = """
290309 package org.example.test;
291310 public class D {
@@ -303,6 +322,7 @@ void x() { //here should be an annotation
303322
304323 @ Test
305324 public void testTryStatementFolding () throws Exception {
325+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
306326 String str = """
307327 package org.example.test;
308328 public class E {
@@ -324,6 +344,7 @@ void x() { //here should be an annotation
324344
325345 @ Test
326346 public void testWhileStatementFolding () throws Exception {
347+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
327348 String str = """
328349 package org.example.test;
329350 public class F {
@@ -341,6 +362,7 @@ void x() { //here should be an annotation
341362
342363 @ Test
343364 public void testForStatementFolding () throws Exception {
365+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
344366 String str = """
345367 package org.example.test;
346368 public class G {
@@ -358,6 +380,7 @@ void x() { //here should be an annotation
358380
359381 @ Test
360382 public void testEnhancedForStatementFolding () throws Exception {
383+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
361384 String str = """
362385 package org.example.test;
363386 public class H {
@@ -375,6 +398,7 @@ void x() { //here should be an annotation
375398
376399 @ Test
377400 public void testDoStatementFolding () throws Exception {
401+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
378402 String str = """
379403 package org.example.test;
380404 public class I {
@@ -393,6 +417,7 @@ void x() { //here should be an annotation
393417
394418 @ Test
395419 public void testSynchronizedStatementFolding () throws Exception {
420+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
396421 String str = """
397422 package org.example.test;
398423 public class K {
@@ -410,6 +435,7 @@ void x() { //here should be an annotation
410435
411436 @ Test
412437 public void testLambdaExpressionFolding () throws Exception {
438+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
413439 String str = """
414440 package org.example.test;
415441 import java.util.function.Supplier;
@@ -429,6 +455,8 @@ void x() { //here should be an annotation
429455
430456 @ Test
431457 public void testAnonymousClassDeclarationFolding () throws Exception {
458+ // FIXME this test should work for both foldings. See https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2022
459+ assumeTrue ("Currently broken for the 'old' folding. See https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2022" , newFoldingActive );
432460 String str = """
433461 package org.example.test;
434462 public class M {
@@ -447,6 +475,7 @@ void y() { //here should be an annotation
447475
448476 @ Test
449477 public void testEnumDeclarationFolding () throws Exception {
478+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
450479 String str = """
451480 package org.example.test;
452481 public enum N { //here should be an annotation
@@ -475,6 +504,7 @@ public class O {
475504
476505 @ Test
477506 public void testNestedFolding () throws Exception {
507+ assumeTrue ("Only doable with the new folding" , newFoldingActive );
478508 String str = """
479509 package org.example.test;
480510 public class P {
0 commit comments