-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check enum constructor content before removing (#922)
- Loading branch information
Showing
7 changed files
with
198 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums2a.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package jadx.tests.integration.enums; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
import static jadx.tests.integration.enums.TestEnums2a.TestCls.DoubleOperations.DIVIDE; | ||
import static jadx.tests.integration.enums.TestEnums2a.TestCls.DoubleOperations.TIMES; | ||
|
||
public class TestEnums2a extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
|
||
public interface IOps { | ||
double apply(double x, double y); | ||
} | ||
|
||
public enum DoubleOperations implements IOps { | ||
TIMES("*") { | ||
@Override | ||
public double apply(double x, double y) { | ||
return x * y; | ||
} | ||
}, | ||
DIVIDE("/") { | ||
@Override | ||
public double apply(double x, double y) { | ||
return x / y; | ||
} | ||
}; | ||
|
||
private final String op; | ||
|
||
DoubleOperations(String op) { | ||
this.op = op; | ||
} | ||
|
||
public String getOp() { | ||
return op; | ||
} | ||
} | ||
|
||
public void check() { | ||
assertThat(TIMES.getOp()).isEqualTo("*"); | ||
assertThat(DIVIDE.getOp()).isEqualTo("/"); | ||
|
||
assertThat(TIMES.apply(2, 3)).isEqualTo(6); | ||
assertThat(DIVIDE.apply(10, 5)).isEqualTo(2); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.containsOne("TIMES(\"*\") {") | ||
.containsOne("DIVIDE(\"/\")"); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums6.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package jadx.tests.integration.enums; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestEnums6 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
public enum Numbers { | ||
ZERO, | ||
ONE(1); | ||
|
||
private final int n; | ||
|
||
Numbers() { | ||
this(0); | ||
} | ||
|
||
Numbers(int n) { | ||
this.n = n; | ||
} | ||
|
||
public int getN() { | ||
return n; | ||
} | ||
} | ||
|
||
public void check() { | ||
Assertions.assertThat(TestCls.Numbers.ZERO.getN()).isEqualTo(0); | ||
Assertions.assertThat(TestCls.Numbers.ONE.getN()).isEqualTo(1); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.containsOne("ZERO,") | ||
.containsOne("Numbers() {") | ||
.containsOne("ONE(1);"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
jadx-core/src/test/java/jadx/tests/integration/enums/TestEnums7.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package jadx.tests.integration.enums; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.tests.api.IntegrationTest; | ||
|
||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; | ||
|
||
public class TestEnums7 extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
public enum Numbers { | ||
ZERO, | ||
ONE; | ||
|
||
private final int n; | ||
|
||
Numbers() { | ||
this.n = this.name().equals("ZERO") ? 0 : 1; | ||
} | ||
|
||
public int getN() { | ||
return n; | ||
} | ||
} | ||
|
||
public void check() { | ||
assertThat(Numbers.ZERO.getN()).isEqualTo(0); | ||
assertThat(Numbers.ONE.getN()).isEqualTo(1); | ||
} | ||
} | ||
|
||
@Test | ||
public void test() { | ||
assertThat(getClassNode(TestCls.class)) | ||
.code() | ||
.containsOne("ZERO,") | ||
.containsOne("ONE;") | ||
.containsOne("Numbers() {"); | ||
} | ||
} |