Skip to content

Commit

Permalink
[java] Add test with record implementing a interface
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Feb 29, 2020
1 parent 548326d commit f49a6db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void recordPointBeforeJava14PreviewShouldFail() {
public void innerRecords() {
ASTCompilationUnit compilationUnit = java14p.parseResource("Records.java");
List<ASTRecordDeclaration> recordDecls = compilationUnit.findDescendantsOfType(ASTRecordDeclaration.class, true);
Assert.assertEquals(6, recordDecls.size());
Assert.assertEquals(7, recordDecls.size());

ASTRecordDeclaration complex = recordDecls.get(0);
Assert.assertEquals("MyComplex", complex.getName());
Expand Down Expand Up @@ -152,6 +152,11 @@ public void innerRecords() {
ASTRecordDeclaration emptyRec = recordDecls.get(5);
Assert.assertEquals("EmptyRec", emptyRec.getName());
Assert.assertEquals(0, emptyRec.getRecordComponents().size());

ASTRecordDeclaration personRec = recordDecls.get(6);
Assert.assertEquals("PersonRecord", personRec.getName());
ASTImplementsList impl = personRec.getFirstChildOfType(ASTImplementsList.class);
Assert.assertEquals(2, impl.findChildrenOfType(ASTClassOrInterfaceType.class).size());
}

@Test(expected = ParseException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ public static void baz() {
System.out.println(r);
}
}

// see https://www.javaspecialists.eu/archive/Issue276.html
public interface Person {
String firstName();
String lastName();
}
public record PersonRecord(String firstName, String lastName)
implements Person, java.io.Serializable { }
}

0 comments on commit f49a6db

Please sign in to comment.