BAEL-6498 RequiredArgsConstructor Code and Tests (#14281)
* BAEL-6498 RequiredArgsConstructor Code and Tests * BAEL-6498 RequiredArgsConstructor Code and Tests
This commit is contained in:
parent
0ec89aee72
commit
2f0f9d7e47
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.lombok.requiredargsconstructor;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ClassWithFinalMembers {
|
||||
|
||||
private final String stringObject;
|
||||
|
||||
public String getStringObject() {
|
||||
return stringObject;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.baeldung.lombok.requiredargsconstructor;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ClassWithFinalNonNullMembers {
|
||||
|
||||
private final String finalStringObject;
|
||||
@NonNull
|
||||
private String nonNullStringObject;
|
||||
|
||||
private String nonFinalStringObject;
|
||||
|
||||
public String getFinalStringObject() {
|
||||
return finalStringObject;
|
||||
}
|
||||
|
||||
public String getNonNullStringObject() {
|
||||
return nonNullStringObject;
|
||||
}
|
||||
|
||||
public String getNonFinalStringObject() {
|
||||
return nonFinalStringObject;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.lombok.requiredargsconstructor;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ClassWithNonFinalMembers {
|
||||
|
||||
private String stringObject;
|
||||
|
||||
public String getStringObject() {
|
||||
return stringObject;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.lombok.requiredargsconstructor;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class RequiredArgsConstructorUnitTest {
|
||||
@Test
|
||||
void whenClassHasFinalMembers_thenGeneratedConstructorHasParameters() {
|
||||
ClassWithFinalMembers classWithFinalMembers = new ClassWithFinalMembers("dummyString");
|
||||
Assertions.assertNotNull(classWithFinalMembers);
|
||||
Assertions.assertEquals("dummyString", classWithFinalMembers.getStringObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenClassHasNonFinalMembers_thenGeneratedConstructorHasNoParameters() {
|
||||
ClassWithNonFinalMembers classWithNonFinalMembers = new ClassWithNonFinalMembers();
|
||||
Assertions.assertNotNull(classWithNonFinalMembers);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenClassHasFinalAndNonNullMembers_thenGeneratedConstructorHasParameters() {
|
||||
ClassWithFinalNonNullMembers classWithFinalNonNullMembers = new ClassWithFinalNonNullMembers("finalString", "nonNullString");
|
||||
Assertions.assertNotNull(classWithFinalNonNullMembers);
|
||||
Assertions.assertEquals("finalString", classWithFinalNonNullMembers.getFinalStringObject());
|
||||
Assertions.assertEquals("nonNullString", classWithFinalNonNullMembers.getNonNullStringObject());
|
||||
Assertions.assertNull(classWithFinalNonNullMembers.getNonFinalStringObject());
|
||||
}
|
||||
}
|
2
pom.xml
2
pom.xml
|
@ -1297,7 +1297,7 @@
|
|||
<gitflow-incremental-builder.version>3.12.2</gitflow-incremental-builder.version>
|
||||
<maven-jxr-plugin.version>3.0.0</maven-jxr-plugin.version>
|
||||
<maven-pmd-plugin.version>3.19.0</maven-pmd-plugin.version>
|
||||
<lombok.version>1.18.24</lombok.version>
|
||||
<lombok.version>1.18.28</lombok.version>
|
||||
<h2.version>2.1.214</h2.version>
|
||||
<guava.version>31.1-jre</guava.version>
|
||||
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
|
||||
|
|
Loading…
Reference in New Issue