Allow TestCompiler SourceFile to work with records
Update `SourceFile` to try a regex replace to make `record` files look like regular classes. Closes gh-29236
This commit is contained in:
@@ -119,6 +119,33 @@ class SourceFileTests {
|
||||
assertThat(sourceFile.getContent()).isEqualTo(HELLO_WORLD);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClassNameFromSimpleRecord() {
|
||||
SourceFile sourceFile = SourceFile.of("""
|
||||
package com.example.helloworld;
|
||||
|
||||
record HelloWorld(String name) {
|
||||
}
|
||||
""");
|
||||
assertThat(sourceFile.getClassName()).isEqualTo("com.example.helloworld.HelloWorld");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClassNameFromMoreComplexRecord() {
|
||||
SourceFile sourceFile = SourceFile.of("""
|
||||
package com.example.helloworld;
|
||||
|
||||
public record HelloWorld(String name) {
|
||||
|
||||
String getFoo() {
|
||||
return name();
|
||||
}
|
||||
|
||||
}
|
||||
""");
|
||||
assertThat(sourceFile.getClassName()).isEqualTo("com.example.helloworld.HelloWorld");
|
||||
}
|
||||
|
||||
/**
|
||||
* JavaPoet style API with a {@code writeTo} method.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user