|
| 1 | +/* |
| 2 | + * Copyright 2025 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.kotlin.tree; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.Test; |
| 19 | +import org.openrewrite.Issue; |
| 20 | +import org.openrewrite.java.tree.J; |
| 21 | +import org.openrewrite.test.RewriteTest; |
| 22 | + |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; |
| 24 | +import static org.openrewrite.kotlin.Assertions.kotlin; |
| 25 | + |
| 26 | +class PrimitiveTest implements RewriteTest { |
| 27 | + |
| 28 | + @Issue("https://github.com/openrewrite/rewrite-spring/pull/663") |
| 29 | + @Test |
| 30 | + void intZeroValueIsInteger() { |
| 31 | + rewriteRun( |
| 32 | + kotlin( |
| 33 | + """ |
| 34 | + fun foo() { |
| 35 | + val bar = 0 |
| 36 | + } |
| 37 | + """, |
| 38 | + spec -> spec.afterRecipe(cu -> { |
| 39 | + J.MethodDeclaration foo = (J.MethodDeclaration) cu.getStatements().get(0); |
| 40 | + J.VariableDeclarations bar = (J.VariableDeclarations) foo.getBody().getStatements().get(0); |
| 41 | + J.Literal zero = (J.Literal) bar.getVariables().get(0).getInitializer(); |
| 42 | + assertThat(zero.getType().getKeyword()).isEqualTo("int"); |
| 43 | + assertThat(zero.getValue()).isInstanceOf(Integer.class); |
| 44 | + }) |
| 45 | + ) |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + @Issue("https://github.com/openrewrite/rewrite-spring/pull/663") |
| 50 | + @Test |
| 51 | + void longZeroValueIsLong() { |
| 52 | + rewriteRun( |
| 53 | + kotlin( |
| 54 | + """ |
| 55 | + fun foo() { |
| 56 | + val bar = 0L |
| 57 | + } |
| 58 | + """, |
| 59 | + spec -> spec.afterRecipe(cu -> { |
| 60 | + J.MethodDeclaration foo = (J.MethodDeclaration) cu.getStatements().get(0); |
| 61 | + J.VariableDeclarations bar = (J.VariableDeclarations) foo.getBody().getStatements().get(0); |
| 62 | + J.Literal zero = (J.Literal) bar.getVariables().get(0).getInitializer(); |
| 63 | + assertThat(zero.getType().getKeyword()).isEqualTo("long"); |
| 64 | + assertThat(zero.getValue()).isInstanceOf(Long.class); |
| 65 | + }) |
| 66 | + ) |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments