Skip to content

Commit

Permalink
added more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
subyssurendran666 authored and mpalat committed Oct 14, 2024
1 parent 237d983 commit 6298d93
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1402,15 +1402,15 @@ public void testRecord_028() throws Exception {

}

public void testRecord_029() throws Exception {
public void testRecord_029_a() throws Exception {
if (checkAPILevel()) {
return;
}
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);

String code = """
package test1;
public record Test(String name) {
record Test(String name) {
public static Builder builder() {}
public static final class Builder {}
}
Expand All @@ -1432,13 +1432,102 @@ public static final class Builder {}

String reWriteCode = """
package test1;
public record Test(String name) {
record Test(String name) {
public static final class Builder {}
}
""";

assertEqualString(preview, reWriteCode);
}

public void testRecord_029_b() throws Exception {
if (checkAPILevel()) {
return;
}
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);

String code = """
package test1;
public class Test {
public static Builder builder() {}
public static final class Builder {}
}
""";

ICompilationUnit cu= pack1.createCompilationUnit("Test.java", code, false, null);

CompilationUnit astRoot= createAST(cu);
ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());

assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
List <TypeDeclaration> methods= astRoot.types();
MethodDeclaration methodDecl= findMethodDeclaration(methods.get(0), "builder");
{
rewrite.remove(methodDecl, null);
}

String preview= evaluateRewrite(cu, rewrite);

String reWriteCode = """
package test1;
public class Test {
public static final class Builder {}
}
""";

assertEqualString(preview, reWriteCode);
}

public void testRecord_029_c() throws Exception {
if (checkAPILevel()) {
return;
}
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);

String code = """
package test1;
record Test(String name) {
public static Builder builder() {}
public static final class Builder {}
public static Builder builderNew() {}
public static final class builderNew {
builderNew(){
System.out.println("Test");
}
}
}
""";

ICompilationUnit cu= pack1.createCompilationUnit("Test.java", code, false, null);

CompilationUnit astRoot= createAST(cu);
ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());

assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
List <RecordDeclaration> methods= astRoot.types();
MethodDeclaration methodDecl= findMethodDeclaration(methods.get(0), "builder");
MethodDeclaration methodDeclNew= findMethodDeclaration(methods.get(0), "builderNew");
{
rewrite.remove(methodDecl, null);
rewrite.remove(methodDeclNew, null);
}

String preview= evaluateRewrite(cu, rewrite);

String reWriteCode = """
package test1;
record Test(String name) {
public static final class Builder {}
public static final class builderNew {
builderNew(){
System.out.println("Test");
}
}
}
""";

assertEqualString(preview, reWriteCode);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -3350,7 +3350,7 @@ public static boolean isSupportedJavaVersion(String version) {
*
* @return {@code true} if the given string represents Java language version is fully supported by Eclipse compiler
* @see #getAllJavaSourceVersionsSupportedByCompiler()
* @since 3.40
* @since 3.39
*/
public static boolean isJavaSourceVersionSupportedByCompiler(String version) {
if(version == null || version.isBlank()) {
Expand Down

0 comments on commit 6298d93

Please sign in to comment.