[Lombok] Convert tests with compilation errors to diagnostic tests

This commit is contained in:
Dmitriy Novozhilov
2022-05-27 10:53:01 +03:00
committed by teamcity
parent fb57e1ecd5
commit 430ea414a9
42 changed files with 413 additions and 199 deletions
+64
View File
@@ -0,0 +1,64 @@
// FILE: AccessorsTest.java
import lombok.*;
import lombok.experimental.*;
@Getter
@Setter
@Accessors(prefix = { "f", "field" })
public class AccessorsTest {
private int age = 10;
private int fTarget = 42;
private String fieldValue;
@Accessors
private boolean isHuman;
private boolean fPrefixedBoolean;
@Accessors
private Boolean isNonPrimitiveHuman;
static void test()
{
val obj = new AccessorsTest ();
obj.getTarget();
obj.setTarget(34);
obj.getValue();
obj.setValue("sdf");
obj.isHuman();
obj.setHuman(true);
obj.isPrefixedBoolean();
obj.setPrefixedBoolean(false);
obj.getIsNonPrimitiveHuman();
obj.setIsNonPrimitiveHuman(false);
}
}
// FILE: test.kt
fun box(): String {
val obj = AccessorsTest()
obj.getTarget()
obj.setTarget(34)
obj.getValue()
obj.setValue("sdf")
obj.isHuman()
obj.setHuman(true)
obj.isPrefixedBoolean()
obj.setPrefixedBoolean(false)
obj.getIsNonPrimitiveHuman()
obj.setIsNonPrimitiveHuman(false)
return "OK"
}
@@ -0,0 +1,64 @@
// FILE: AccessorsTest.java
import lombok.*;
import lombok.experimental.*;
@Getter @Setter
public class AccessorsTest {
private int age = 10;
private int fTarget = 42;
private String fieldValue;
@Accessors(prefix = {})
private boolean isHuman;
private boolean fPrefixedBoolean;
@Accessors(prefix = {})
private Boolean isNonPrimitiveHuman;
static void test() {
val obj = new AccessorsTest();
obj.getTarget();
obj.setTarget(34);
obj.getValue();
obj.setValue("sdf");
obj.isHuman();
obj.setHuman(true);
obj.isPrefixedBoolean();
obj.setPrefixedBoolean(false);
obj.getIsNonPrimitiveHuman();
obj.setIsNonPrimitiveHuman(false);
}
}
// FILE: test.kt
fun box(): String {
val obj = AccessorsTest()
obj.getTarget()
obj.setTarget(34)
obj.getValue()
obj.setValue("sdf")
obj.isHuman()
obj.setHuman(true)
obj.isPrefixedBoolean()
obj.setPrefixedBoolean(false)
obj.getIsNonPrimitiveHuman()
obj.setIsNonPrimitiveHuman(false)
return "OK"
}
// FILE: lombok.config
lombok.accessors.prefix += f
lombok.accessors.prefix+=field
+25
View File
@@ -0,0 +1,25 @@
// FILE: ConstructorExample.java
import lombok.*;
@AllArgsConstructor
public class ConstructorExample {
@Getter @Setter private int age = 10;
@Getter(AccessLevel.PROTECTED) private String name;
private boolean otherField;
static void javaUsage() {
val generated = new ConstructorExample(12, "sdf", true);
}
}
// FILE: test.kt
fun box(): String {
val generated = ConstructorExample(12, "sdf", true)
return "OK"
}
+31
View File
@@ -0,0 +1,31 @@
// FILE: ConstructorExample.java
import lombok.*;
@AllArgsConstructor(staticName = "of")
public class ConstructorExample {
@Getter @Setter private int age = 10;
@Getter(AccessLevel.PROTECTED) private String name;
private boolean otherField;
public ConstructorExample(String arg) {
}
static void javaUsage() {
ConstructorExample existing = new ConstructorExample("existing");
ConstructorExample generated = ConstructorExample.of(45, "234", false);
}
}
// FILE: test.kt
fun box(): String {
val existing: ConstructorExample = ConstructorExample("existing")
val generated: ConstructorExample = ConstructorExample.of(45, "234", false)
return "OK"
}
+32
View File
@@ -0,0 +1,32 @@
// FILE: GetterTest.java
import lombok.*;
@Getter @Setter
public class GetterTest {
private String name;
private int age;
static void test() {
val obj = new GetterTest();
GetterTest ref = obj.name("some").age(34);
obj.name();
obj.age();
}
}
// FILE: test.kt
fun box(): String {
val obj = GetterTest()
val ref: GetterTest = obj.name("some").age(34)
obj.name()
obj.age()
return "OK"
}
// FILE: lombok.config
lombok.accessors.fluent=true
#lombok.accessors.chain=false
+35
View File
@@ -0,0 +1,35 @@
// FILE: GetterTest.java
import lombok.*;
import lombok.experimental.*;
@Getter @Setter
public class GetterTest {
private String name;
private int age;
@Accessors(chain = true)
private boolean fluent;
static void test() {
val obj = new GetterTest();
GetterTest ref = obj.fluent(true);
obj.name();
obj.age();
}
}
// FILE: test.kt
fun box(): String {
val obj = GetterTest()
val ref: GetterTest = obj.fluent(true)
obj.name()
obj.age()
return "OK"
}
// FILE: lombok.config
lombok.accessors.fluent=true
lombok.accessors.chain=false
+28
View File
@@ -0,0 +1,28 @@
// FILE: GetterTest.java
import lombok.AccessLevel;
import lombok.Getter;
public class GetterTest {
@Getter private boolean primitiveBoolean;
void test() {
getPrimitiveBoolean();
}
}
// FILE: test.kt
fun box(): String {
val obj = GetterTest()
obj.primitiveBoolean
obj.getPrimitiveBoolean()
return "OK"
}
// FILE: lombok.config
#lombok config keys are case insensitive
lombok.getter.noisprefix=true
+27
View File
@@ -0,0 +1,27 @@
// FILE: GetterTest.java
import lombok.AccessLevel;
import lombok.Getter;
public class GetterTest {
@Getter private boolean primitiveBoolean;
void test() {
getPrimitiveBoolean();
}
}
// FILE: test.kt
fun box(): String {
val obj = GetterTest()
obj.primitiveBoolean
obj.getPrimitiveBoolean()
return "OK"
}
// FILE: lombok.config
lombok.getter.noIsPrefix=true
+43
View File
@@ -0,0 +1,43 @@
// FILE: DataExample.java
import lombok.*;
@Data public class DataExample {
private final String name;
@Setter(AccessLevel.PACKAGE) private int age;
private double score;
private String[] tags;
@ToString(includeFieldNames=true)
@Data(staticConstructor="of")
public static class Exercise<T> {
private final String name;
private final T value;
}
public static void usage() {
val obj = new DataExample("name");
obj.getName();
obj.getTags();
obj.setScore(1.5);
Exercise<Integer> ex = Exercise.of("name", 12);
}
}
// FILE: test.kt
fun box(): String {
val obj = DataExample("name")
obj.getName()
assertEquals(obj.name, "name")
obj.getTags()
val tags = obj.tags
obj.setScore(1.5)
assertEquals(obj.score, 1.5)
obj.score = 2.5
assertEquals(obj.score, 2.5)
val ex: DataExample.Exercise<Int> = DataExample.Exercise.of("name", 12)
return "OK"
}
+38
View File
@@ -0,0 +1,38 @@
// FILE: GenericsTest.java
import lombok.*;
import java.util.*;
public class GenericsTest<A, B> {
@Getter private int age = 10;
@Getter @Setter private A fieldA;
@Getter private B fieldB;
@Setter private Map<A, B> fieldC;
static void test() {
val obj = new GenericsTest<String, Boolean>();
int age = obj.getAge();
String a = obj.getFieldA();
obj.setFieldA("fooo");
Boolean b = obj.getFieldB();
obj.setFieldC(new HashMap<String, Boolean>());
}
}
// FILE: test.kt
fun box(): String {
val obj = GenericsTest<String, Boolean>()
val age: Int = obj.getAge();
obj.setFieldA("fooo");
val a: String = obj.getFieldA();
val b: Boolean? = obj.getFieldB();
obj.setFieldC(java.util.HashMap<String, Boolean>());
return "OK"
}
+28
View File
@@ -0,0 +1,28 @@
// FILE: ConstructorExample.java
import lombok.*;
@AllArgsConstructor
@RequiredArgsConstructor
public class ConstructorExample<A, B> {
@Getter @Setter private int age = 10;
@Getter private final A name;
private B otherField;
static void javaUsage() {
val generated = new ConstructorExample<Long, Boolean>(12, 42L, true);
val generatedReq = new ConstructorExample<String, Boolean>("234");
}
}
// FILE: test.kt
fun box(): String {
val generated = ConstructorExample<Long, Boolean>(12, 42L, true)
val generatedReq = ConstructorExample<String, Boolean>("234");
return "OK"
}
@@ -0,0 +1,30 @@
// FILE: ConstructorExample.java
import lombok.*;
@AllArgsConstructor(staticName = "of")
@RequiredArgsConstructor(staticName = "of")
public class ConstructorExample<A, B> {
@Getter @Setter private int age = 10;
@Getter private final A name;
private B otherField;
static void javaUsage() {
ConstructorExample<Long, Boolean> generated = ConstructorExample.of(12, 42L, true);
ConstructorExample<String, Boolean> generatedReq = ConstructorExample.of("234");
}
}
// FILE: test.kt
fun box(): String {
val generated: ConstructorExample<Long, Boolean> = ConstructorExample.of(12, 42L, true)
assertEquals(generated.name, 42L)
val generatedReq: ConstructorExample<String, Boolean> = ConstructorExample.of("234")
assertEquals(generatedReq.name, "234")
return "OK"
}
+49
View File
@@ -0,0 +1,49 @@
// FILE: FluentTest.java
import lombok.AccessLevel;
import lombok.Getter;
import lombok.experimental.Accessors;
@Accessors(fluent = true)
public class FluentTest {
@Getter private int age = 10;
@Getter @Accessors private int overrideAnnotation = 10;
@Getter(AccessLevel.PROTECTED) private String name;
@Getter private boolean primitiveBoolean;
@Getter private Boolean boxedBoolean;
void test() {
age();
primitiveBoolean();
getOverrideAnnotation();
}
}
// FILE: test.kt
fun box(): String {
val obj = FluentTest()
assertEquals(obj.age(), 10)
obj.primitiveBoolean()
obj.boxedBoolean()
obj.overrideAnnotation
obj.getOverrideAnnotation()
OverridenGetterTest().usage()
return "OK"
}
class OverridenGetterTest : FluentTest() {
fun usage() {
name()
}
}
+30
View File
@@ -0,0 +1,30 @@
// FILE: ConstructorExample.java
import lombok.*;
@NoArgsConstructor
public class ConstructorExample {
public ConstructorExample(String arg) {
}
@Getter @Setter private int age = 10;
@Getter(AccessLevel.PROTECTED) private String name;
static void javaUsage() {
val existing = new ConstructorExample("existing");
val generated = new ConstructorExample();
}
}
// FILE: test.kt
fun box(): String {
val existing = ConstructorExample("existing")
val generated = ConstructorExample()
return "OK"
}
+30
View File
@@ -0,0 +1,30 @@
// FILE: ConstructorExample.java
import lombok.*;
@NoArgsConstructor(staticName = "make")
public class ConstructorExample {
public ConstructorExample(String arg) {
}
@Getter @Setter private int age = 10;
@Getter(AccessLevel.PROTECTED) private String name;
static void javaUsage() {
ConstructorExample existing = new ConstructorExample("existing");
ConstructorExample generated = ConstructorExample.make();
}
}
// FILE: test.kt
fun box(): String {
val existing: ConstructorExample = ConstructorExample("existing")
val generated: ConstructorExample = ConstructorExample.make()
return "OK"
}
+22
View File
@@ -0,0 +1,22 @@
// FILE: GetterSetterExample.java
import lombok.*;
import org.jetbrains.annotations.*;
@Getter @Setter
public class GetterSetterExample {
@NotNull
private Integer age = 10;
@Nullable
private String name;
}
// FILE: test.kt
fun box(): String {
val obj = GetterSetterExample()
val age: Int = obj.getAge()
val name: String? = obj.getName()
return "OK"
}
+19
View File
@@ -0,0 +1,19 @@
// KT-47455
// FILE: ParentClass.java
public abstract class ParentClass {
int id;
}
// FILE: ChildClass.java
import lombok.*;
@RequiredArgsConstructor
public class ChildClass extends ParentClass {}
// FILE: test.kt
fun box(): String {
ChildClass::class
return "OK"
}
+41
View File
@@ -0,0 +1,41 @@
// FILE: ConstructorExample.java
import lombok.*;
@RequiredArgsConstructor
public class ConstructorExample {
//not required
@Getter @Setter private int age;
//required final
@Getter @Setter private final String foo;
//not required final, because has initializer
@Getter @Setter private final int bar = 234;
//not required
@Getter(AccessLevel.PROTECTED) private String name;
//required by annotation
@NonNull
private boolean otherField;
//not required by annotation, because has initializer
@NonNull
private Long zzzz = 23L;
static void javaUsage() {
ConstructorExample generated = new ConstructorExample("foo", true);
}
}
// FILE: test.kt
fun box(): String {
val generated = ConstructorExample("foo", true)
assertEquals(generated.foo, "foo")
return "OK"
}
@@ -0,0 +1,42 @@
// FILE: ConstructorExample.java
import lombok.*;
@RequiredArgsConstructor(staticName = "build")
public class ConstructorExample {
//not required
@Getter @Setter private int age;
//required final
@Getter @Setter private final String foo;
//not required final, because has initializer
@Getter @Setter private final int bar = 234;
//not required
@Getter(AccessLevel.PROTECTED) private String name;
//required by annotation
@NonNull
private boolean otherField;
//not required by annotation, because has initializer
@NonNull
private Long zzzz = 23L;
@NonNull Integer somethingElse;
static void javaUsage() {
ConstructorExample generated = ConstructorExample.build("foo", true, 12);
}
}
// FILE: test.kt
fun box(): String {
val generated = ConstructorExample.build("foo", true, 12)
assertEquals(generated.foo, "foo")
return "OK"
}
+37
View File
@@ -0,0 +1,37 @@
// FILE: SetterTest.java
import lombok.AccessLevel;
import lombok.Setter;
import lombok.Getter;
import lombok.experimental.Accessors;
@Setter
@Getter
public class SetterTest {
@Accessors(fluent = true) private int fluent;
@Accessors(chain = true) private String chained;
@Accessors(chain = true, fluent = true) private String whyNotBoth;
void test() {
fluent(12);
setChained("zz").getChained();
whyNotBoth("zzz").whyNotBoth();
}
}
// FILE: test.kt
fun box(): String {
val obj = SetterTest()
obj.fluent(12)
assertEquals(obj.fluent(), 12)
obj.setChained("zz").getChained()
assertEquals(obj.getChained(), "zz")
obj.whyNotBoth("zzz").whyNotBoth()
assertEquals(obj.whyNotBoth(), "zzz")
return "OK"
}
+21
View File
@@ -0,0 +1,21 @@
// FILE: GetterSetterExample.java
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
public class GetterSetterExample {
@Getter @Setter private int age = 10;
@Getter(AccessLevel.PROTECTED) private String name;
}
// FILE: test.kt
fun box(): String {
val obj = GetterSetterExample()
val getter = obj.getAge()
val property = obj.age
return "OK"
}
+43
View File
@@ -0,0 +1,43 @@
// FILE: ValueExample.java
import lombok.*;
@Value public class ValueExample {
private final String name;
private int age;
private double score;
@ToString(includeFieldNames=true)
@Value(staticConstructor="of")
public static class Exercise<T> {
private final String name;
private T value;
}
public static void usage() {
val obj = new ValueExample("name", 12, 4.5);
obj.getName();
obj.getAge();
obj.getScore();
Exercise<Integer> ex = Exercise.of("name", 12);
ex.getName();
ex.getValue();
}
}
// FILE: test.kt
fun box(): String {
val obj = ValueExample("name", 12, 4.5)
assertEquals(obj.getName(), "name")
assertEquals(obj.name, "name")
assertEquals(obj.getAge(), 12)
assertEquals(obj.age, 12)
assertEquals(obj.score, 4.5)
val ex: ValueExample.Exercise<Int> = ValueExample.Exercise.of("nam1e", 42)
assertEquals(ex.name, "nam1e")
assertEquals(ex.value, 42)
return "OK"
}
+26
View File
@@ -0,0 +1,26 @@
// FILE: WithExample.java
import lombok.*;
@AllArgsConstructor
@NoArgsConstructor
public class WithExample {
@Getter @With private int age = 10;
@Getter @With private String name;
public static WithExample test() {
return new WithExample().withAge(16).withName("fooo");
}
}
// FILE: test.kt
fun box(): String {
val obj: WithExample = WithExample().withAge(16).withName("fooo")
assertEquals(obj.getName(), "fooo")
assertEquals(obj.age, 16)
return "OK"
}