|
| 1 | +/* |
| 2 | + * Copyright 2024 the original author or authors. |
| 3 | + * <p> |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * <p> |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * <p> |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.openrewrite.java.migrate; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | +import org.openrewrite.DocumentExample; |
| 20 | +import org.openrewrite.test.RecipeSpec; |
| 21 | +import org.openrewrite.test.RewriteTest; |
| 22 | + |
| 23 | +import static org.openrewrite.java.Assertions.java; |
| 24 | + |
| 25 | +class RemovedModifierAndConstantBootstrapsConstructorsTest implements RewriteTest { |
| 26 | + |
| 27 | + @Override |
| 28 | + public void defaults(RecipeSpec spec) { |
| 29 | + spec.recipeFromResource("/META-INF/rewrite/java-version-17.yml", "org.openrewrite.java.migrate.RemovedModifierAndConstantBootstrapsConstructors"); |
| 30 | + } |
| 31 | + |
| 32 | + @DocumentExample |
| 33 | + @Test |
| 34 | + void moveToStaticTest() { |
| 35 | + rewriteRun( |
| 36 | + //language=java |
| 37 | + java( |
| 38 | + """ |
| 39 | + import java.lang.invoke.ConstantBootstraps; |
| 40 | + import java.lang.reflect.Modifier; |
| 41 | + |
| 42 | + class RemovedModifierAndConstantBootstrapsConstructorsApp { |
| 43 | + public void testModifier() throws Exception { |
| 44 | + Modifier modifier = new Modifier(); |
| 45 | + modifier.classModifiers(); |
| 46 | + modifier.fieldModifiers(); |
| 47 | + modifier.isFinal(1); |
| 48 | + modifier.isStatic(1); |
| 49 | + Modifier.isPublic(0); |
| 50 | + } |
| 51 | + public void testConstantBootstraps() throws Exception { |
| 52 | + ConstantBootstraps constantBootstraps = new ConstantBootstraps(); |
| 53 | + constantBootstraps.enumConstant(null,null,null); |
| 54 | + constantBootstraps.primitiveClass(null,null,null); |
| 55 | + ConstantBootstraps.nullConstant(null, null, null); |
| 56 | + } |
| 57 | + } |
| 58 | + """, |
| 59 | + """ |
| 60 | + import java.lang.invoke.ConstantBootstraps; |
| 61 | + import java.lang.reflect.Modifier; |
| 62 | + |
| 63 | + class RemovedModifierAndConstantBootstrapsConstructorsApp { |
| 64 | + public void testModifier() throws Exception { |
| 65 | + Modifier modifier = new Modifier(); |
| 66 | + Modifier.classModifiers(); |
| 67 | + Modifier.fieldModifiers(); |
| 68 | + Modifier.isFinal(1); |
| 69 | + Modifier.isStatic(1); |
| 70 | + Modifier.isPublic(0); |
| 71 | + } |
| 72 | + public void testConstantBootstraps() throws Exception { |
| 73 | + ConstantBootstraps constantBootstraps = new ConstantBootstraps(); |
| 74 | + ConstantBootstraps.enumConstant(null,null,null); |
| 75 | + ConstantBootstraps.primitiveClass(null,null,null); |
| 76 | + ConstantBootstraps.nullConstant(null, null, null); |
| 77 | + } |
| 78 | + } |
| 79 | + """ |
| 80 | + ) |
| 81 | + ); |
| 82 | + } |
| 83 | +} |
0 commit comments