Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
test: Add unit test for record builder
Browse files Browse the repository at this point in the history
  • Loading branch information
DESKTOP-JF1FCFM\zzBBc committed Aug 30, 2023
1 parent 5d5da3b commit 5d96079
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/java/com/squareup/javapoet/JavaFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,26 @@ private TypeSpec importStaticTypeSpec(String name) {
+ "}\n");
}

@Test
public void recordNoField() {
String source = JavaFile.builder("com.squareup.tacos", TypeSpec.recordBuilder("Taco").build())
.skipJavaLangImports(true).build().toString();
assertThat(source).isEqualTo(
"" + "package com.squareup.tacos;\n" + "\n" + "record Taco() {\n" + "}\n" + "");
}

@Test
public void recordTwoField() {
String source = JavaFile
.builder("com.squareup.tacos",
TypeSpec.recordBuilder("Taco")
.addField(FieldSpec.builder(String.class, "name").build())
.addField(FieldSpec.builder(Integer.class, "code").build()).build())
.skipJavaLangImports(true).build().toString();
assertThat(source).isEqualTo("" + "package com.squareup.tacos;\n" + "\n"
+ "record Taco(String name, Integer code) {\n" + "}\n" + "");
}

@Test public void conflictingImports() throws Exception {
String source = JavaFile.builder("com.squareup.tacos",
TypeSpec.classBuilder("Taco")
Expand Down

0 comments on commit 5d96079

Please sign in to comment.