Java 11498 (#12382)
* added parent lombok-modules * added lombok submodule to parent lombok-modules * added lombok-2 submodule to parent lombok-modules * added lombok-custom submodule to parent lombok-modules * delete lombok submodules that were moved across Co-authored-by: panagiotiskakos <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
panagiotiskakos
parent
033ddb7a41
commit
02c9bdff35
@@ -0,0 +1,3 @@
|
||||
## Project Lombok
|
||||
|
||||
This module contains modules about project lombok
|
||||
@@ -0,0 +1,11 @@
|
||||
## Project Lombok
|
||||
|
||||
This module contains articles about Project Lombok.
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Using Lombok’s @Accessors Annotation](https://www.baeldung.com/lombok-accessors)
|
||||
- [Declaring Val and Var Variables in Lombok](https://www.baeldung.com/java-lombok-val-var)
|
||||
- [Lombok Using @With Annotations](https://www.baeldung.com/lombok-with-annotations)
|
||||
- [Lombok's @ToString Annotation](https://www.baeldung.com/lombok-tostring)
|
||||
- More articles: [[<-- prev]](../lombok)
|
||||
@@ -0,0 +1,2 @@
|
||||
config.stopBubbling = true
|
||||
lombok.experimental.flagUsage = warning
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>lombok-2</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>lombok-2</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>lombok-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.lombok.accessors.model;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class BasicAccount {
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
|
||||
public BigDecimal getBalance() {
|
||||
return this.balance;
|
||||
}
|
||||
|
||||
public void setBalance(BigDecimal newBalance) {
|
||||
this.balance = newBalance;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String accountName) {
|
||||
this.name = accountName;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.lombok.accessors.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Accessors(chain = true)
|
||||
@Getter
|
||||
@Setter
|
||||
public class ChainedAccount {
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.lombok.accessors.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Accessors(fluent = true, chain = true)
|
||||
@Getter
|
||||
@Setter
|
||||
public class ChainedFluentAccount {
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.lombok.accessors.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Accessors(fluent = true, chain = false)
|
||||
@Getter
|
||||
@Setter
|
||||
public class FluentAccount {
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.lombok.accessors.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
@Accessors(prefix = {"s", "bd"})
|
||||
@Getter
|
||||
@Setter
|
||||
public class PrefixedAccount {
|
||||
private String sName;
|
||||
private BigDecimal bdBalance;
|
||||
|
||||
@Accessors(prefix = "s_")
|
||||
private String s_notes;
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.lombok.accessors.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Accessors(prefix = {"s", "bd"}, fluent = true)
|
||||
@Getter
|
||||
@Setter
|
||||
public class PrefixedFluentAccount {
|
||||
private String sName;
|
||||
private BigDecimal bdBalance;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.lombok.accessors.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class StandardAccount {
|
||||
private String name;
|
||||
private BigDecimal balance;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.baeldung.lombok.tostring;
|
||||
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
public class Account {
|
||||
|
||||
private String name;
|
||||
|
||||
// render this field before any others (the highest ranked)
|
||||
@ToString.Include(rank = 1)
|
||||
private String id;
|
||||
|
||||
@ToString.Exclude
|
||||
private String accountNumber;
|
||||
|
||||
// automatically excluded
|
||||
private String $ignored;
|
||||
|
||||
@ToString.Include
|
||||
String description() {
|
||||
return "Account description";
|
||||
}
|
||||
|
||||
public String getAccountNumber() {
|
||||
return accountNumber;
|
||||
}
|
||||
|
||||
public void setAccountNumber(String accountNumber) {
|
||||
this.accountNumber = accountNumber;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String get$ignored() {
|
||||
return $ignored;
|
||||
}
|
||||
|
||||
public void set$ignored(String value) {
|
||||
this.$ignored = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.lombok.tostring;
|
||||
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
public enum AccountType {
|
||||
CHECKING,
|
||||
SAVING
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.lombok.tostring;
|
||||
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString
|
||||
public class RewardAccount extends Account {
|
||||
|
||||
private String rewardAccountId;
|
||||
|
||||
private Object[] relatedAccounts;
|
||||
|
||||
public String getRewardAccountId() {
|
||||
return rewardAccountId;
|
||||
}
|
||||
|
||||
public void setRewardAccountId(String rewardAccountId) {
|
||||
this.rewardAccountId = rewardAccountId;
|
||||
}
|
||||
|
||||
public Object[] getRelatedAccounts() {
|
||||
return relatedAccounts;
|
||||
}
|
||||
|
||||
public void setRelatedAccounts(Object[] relatedAccounts) {
|
||||
this.relatedAccounts = relatedAccounts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.lombok.tostring;
|
||||
|
||||
import lombok.ToString;
|
||||
|
||||
@ToString(callSuper = true)
|
||||
public class SavingAccount extends Account {
|
||||
|
||||
private String savingAccountId;
|
||||
|
||||
public String getSavingAccountId() {
|
||||
return savingAccountId;
|
||||
}
|
||||
|
||||
public void setSavingAccountId(String savingAccountId) {
|
||||
this.savingAccountId = savingAccountId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.baeldung.lombok.valvar;
|
||||
|
||||
import lombok.val;
|
||||
import lombok.var;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ValExample {
|
||||
public Class name() {
|
||||
val name = "name";
|
||||
System.out.println("Name: " + name);
|
||||
return name.getClass();
|
||||
}
|
||||
|
||||
public Class age() {
|
||||
val age = Integer.valueOf(30);
|
||||
System.out.println("Age: " + age);
|
||||
return age.getClass();
|
||||
}
|
||||
|
||||
public Class listOf() {
|
||||
val agenda = new ArrayList<String>();
|
||||
agenda.add("Day 1");
|
||||
System.out.println("Agenda: " + agenda);
|
||||
return agenda.getClass();
|
||||
}
|
||||
|
||||
public Class mapOf() {
|
||||
val books = new HashMap<Integer, String>();
|
||||
books.put(1, "Book 1");
|
||||
books.put(2, "Book 2");
|
||||
System.out.println("Books:");
|
||||
for (val entry : books.entrySet()) {
|
||||
System.out.printf("- %d. %s\n", entry.getKey(), entry.getValue());
|
||||
}
|
||||
return books.getClass();
|
||||
}
|
||||
|
||||
public Class compoundTypes(boolean isArray) {
|
||||
val compound = isArray ? new ArrayList<String>() : new HashSet<String>();
|
||||
return compound.getClass();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.lombok.valvar;
|
||||
|
||||
import lombok.var;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class VarExample {
|
||||
public String name() {
|
||||
var name = "name";
|
||||
name = "newName";
|
||||
System.out.println("Name: " + name);
|
||||
return name;
|
||||
}
|
||||
|
||||
public Integer age() {
|
||||
var age = Integer.valueOf(30);
|
||||
age = 35;
|
||||
System.out.println("Age: " + age);
|
||||
return age;
|
||||
}
|
||||
|
||||
public ArrayList<String> listOf() {
|
||||
var agenda = new ArrayList<String>();
|
||||
agenda.add("Day 1");
|
||||
agenda = new ArrayList<String>(Arrays.asList("Day 2"));
|
||||
System.out.println("Agenda: " + agenda);
|
||||
return agenda;
|
||||
}
|
||||
|
||||
public Map<Integer, String> mapOf() {
|
||||
var books = new HashMap<Integer, String>();
|
||||
books.put(1, "Book 1");
|
||||
books.put(2, "Book 2");
|
||||
books = new HashMap<Integer, String>();
|
||||
books.put(3, "Book 3");
|
||||
books.put(4, "Book 4");
|
||||
|
||||
System.out.println("Books:");
|
||||
for (var entry : books.entrySet()) {
|
||||
System.out.printf("- %d. %s\n", entry.getKey(), entry.getValue());
|
||||
}
|
||||
return books;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
lombok.var.flagUsage = warning
|
||||
lombok.val.flagUsage = warning
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.lombok.with;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.With;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public abstract class Device {
|
||||
private final String serial;
|
||||
@With
|
||||
private final boolean isInspected;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.lombok.with;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.With;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Holder {
|
||||
@With
|
||||
private String variableA;
|
||||
@With
|
||||
private String _variableB;
|
||||
@With
|
||||
private String $variableC;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.lombok.with;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.With;
|
||||
|
||||
@With
|
||||
@AllArgsConstructor
|
||||
public class ImprovedUser {
|
||||
@NonNull
|
||||
private final String username;
|
||||
@NonNull
|
||||
private final String emailAddress;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.lombok.with;
|
||||
|
||||
public class KioskDevice extends Device {
|
||||
|
||||
public KioskDevice(String serial, boolean isInspected) {
|
||||
super(serial, isInspected);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device withInspected(boolean isInspected) {
|
||||
return new KioskDevice(getSerial(), isInspected);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.lombok.with;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.With;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Stock {
|
||||
@With
|
||||
private String sku;
|
||||
private int stockCount;
|
||||
|
||||
public Stock withSku(String sku) {
|
||||
return new Stock("mod-" + sku, stockCount);
|
||||
}
|
||||
|
||||
public Stock withSKU(String... sku) {
|
||||
return sku == null || sku.length == 0 ?
|
||||
new Stock("unknown", stockCount) :
|
||||
new Stock("mod-" + sku[0], stockCount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.lombok.with;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.With;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class User {
|
||||
private final String username;
|
||||
private final String emailAddress;
|
||||
@With
|
||||
private final boolean isAuthenticated;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.baeldung.lombok.accessors;
|
||||
|
||||
import com.baeldung.lombok.accessors.model.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class AccessorsUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenBasicAccount_thenUseBasicAccessors() {
|
||||
BasicAccount account = new BasicAccount();
|
||||
account.setName("Basic Accessors");
|
||||
account.setBalance(BigDecimal.TEN);
|
||||
|
||||
assertEquals("Basic Accessors", account.getName());
|
||||
assertEquals(BigDecimal.TEN, account.getBalance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenFluentAccount_thenUseFluentAccessors() {
|
||||
FluentAccount account = new FluentAccount();
|
||||
account.name("Fluent Account");
|
||||
account.balance(BigDecimal.TEN);
|
||||
|
||||
assertEquals("Fluent Account", account.name());
|
||||
assertEquals(BigDecimal.TEN, account.balance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenChainedAccount_thenUseChainedAccessors() {
|
||||
ChainedAccount account = new ChainedAccount();
|
||||
account.setName("Chained Account").setBalance(BigDecimal.TEN);
|
||||
|
||||
assertEquals("Chained Account", account.getName());
|
||||
assertEquals(BigDecimal.TEN, account.getBalance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenChainedFluentAccount_thenUseChainedFluentAccessors() {
|
||||
ChainedFluentAccount account = new ChainedFluentAccount()
|
||||
.name("Fluent Account")
|
||||
.balance(BigDecimal.TEN);
|
||||
|
||||
assertEquals("Fluent Account", account.name());
|
||||
assertEquals(BigDecimal.TEN, account.balance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPrefixedAccount_thenRemovePrefixFromAccessors() {
|
||||
PrefixedAccount account = new PrefixedAccount();
|
||||
account.setName("Prefixed Fields");
|
||||
account.setBalance(BigDecimal.TEN);
|
||||
account.setNotes("Notes");
|
||||
|
||||
assertEquals("Prefixed Fields", account.getName());
|
||||
assertEquals(BigDecimal.TEN, account.getBalance());
|
||||
assertEquals("Notes", account.getNotes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenPrefixedFluentAccount_thenRemovePrefixFromAccessors() {
|
||||
PrefixedFluentAccount account = new PrefixedFluentAccount();
|
||||
account
|
||||
.name("Prefixed Fluent Fields")
|
||||
.balance(BigDecimal.TEN);
|
||||
|
||||
assertEquals("Prefixed Fluent Fields", account.name());
|
||||
assertEquals(BigDecimal.TEN, account.balance());
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.baeldung.lombok.tostring;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ToStringUnitTest {
|
||||
|
||||
@Test
|
||||
void whenPrintObject_thenOutputIsCorrect() {
|
||||
Account account = new Account();
|
||||
account.setId("12345");
|
||||
account.setName("An account");
|
||||
account.setAccountNumber("11111"); // should not be present in output
|
||||
account.set$ignored("ignored value"); // should not be present in output
|
||||
|
||||
assertThat(account.toString())
|
||||
.isEqualTo("Account(id=12345, name=An account, description=Account description)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenPrintSubclassWithSuper_thenOutputIsCorrect() {
|
||||
SavingAccount savingAccount = new SavingAccount();
|
||||
savingAccount.setSavingAccountId("5678");
|
||||
savingAccount.setId("12345");
|
||||
savingAccount.setName("An account");
|
||||
|
||||
assertThat(savingAccount.toString())
|
||||
.isEqualTo("SavingAccount(super=Account(id=12345, name=An account, description=Account description), savingAccountId=5678)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenPrintArrays_thenOutputIsCorrect() {
|
||||
RewardAccount account = new RewardAccount();
|
||||
account.setRewardAccountId("12345");
|
||||
|
||||
// circular ref, just for demonstration
|
||||
Object[] relatedAccounts = new Object[2];
|
||||
relatedAccounts[0] = "54321";
|
||||
relatedAccounts[1] = relatedAccounts;
|
||||
|
||||
account.setRelatedAccounts(relatedAccounts);
|
||||
|
||||
assertThat(account.toString())
|
||||
.isEqualTo("RewardAccount(rewardAccountId=12345, relatedAccounts=[54321, [...]])");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenPrintSubclassWithoutSuper_thenOutputIsCorrect() {
|
||||
RewardAccount rewardAccount = new RewardAccount();
|
||||
rewardAccount.setRewardAccountId("12345");
|
||||
|
||||
assertThat(rewardAccount.toString())
|
||||
.isEqualTo("RewardAccount(rewardAccountId=12345, relatedAccounts=null)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenPrintEnum_thenOutputIsCorrect() {
|
||||
assertThat(AccountType.CHECKING.toString())
|
||||
.isEqualTo("AccountType.CHECKING");
|
||||
|
||||
assertThat(AccountType.SAVING.toString())
|
||||
.isEqualTo("AccountType.SAVING");
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.lombok.valvar;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class ValExampleUnitTest {
|
||||
|
||||
@Test
|
||||
void whenUsingValWithString_thenTheAssignedClassIsCorrect() {
|
||||
ValExample val = new ValExample();
|
||||
assertThat(val.name()).isEqualTo(String.class);
|
||||
assertThat(val.age()).isEqualTo(Integer.class);
|
||||
assertThat(val.listOf()).isEqualTo(ArrayList.class);
|
||||
assertThat(val.mapOf()).isEqualTo(HashMap.class);
|
||||
assertThat(val.compoundTypes(true)).isEqualTo(ArrayList.class);
|
||||
assertThat(val.compoundTypes(false)).isEqualTo(HashSet.class);
|
||||
}
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.lombok.valvar;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class VarExampleUnitTest {
|
||||
|
||||
@Test
|
||||
void whenUsingVarWithString_thenTheAssignedClassIsCorrect() {
|
||||
VarExample varExample = new VarExample();
|
||||
assertThat(varExample.name()).isEqualTo("newName");
|
||||
assertThat(varExample.age()).isEqualTo(35);
|
||||
assertThat("Day 2").isIn(varExample.listOf());
|
||||
assertThat(varExample.mapOf()).containsValue("Book 3");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.lombok.with;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
|
||||
public class HolderUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenWithMethodsGenerated_thenUsable() {
|
||||
Holder value = new Holder("a", "b");
|
||||
|
||||
Holder valueModifiedA = value.withVariableA("mod-a");
|
||||
Holder valueModifiedB = value.with_variableB("mod-b");
|
||||
// Holder valueModifiedC = value.with$VariableC("mod-c"); not possible
|
||||
|
||||
assertNotSame(valueModifiedA, value);
|
||||
assertNotSame(valueModifiedB, value);
|
||||
assertEquals("mod-a", valueModifiedA.getVariableA());
|
||||
assertEquals("mod-b", valueModifiedB.get_variableB());
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user