Delombok code.

Closes #2286
This commit is contained in:
Mark Paluch
2023-07-07 14:51:03 +02:00
parent 18030f9171
commit aa7262b038
38 changed files with 989 additions and 231 deletions

View File

@@ -18,8 +18,6 @@ package org.springframework.data.rest.core;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import lombok.Value;
import java.net.URI;
import java.util.List;
import java.util.Optional;
@@ -49,6 +47,7 @@ import org.springframework.data.rest.core.UriToEntityConverterUnitTests.JMolecul
import org.springframework.data.util.Streamable;
import org.springframework.data.util.TypeInformation;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.util.ObjectUtils;
/**
* Unit tests for {@link UriToEntityConverter}.
@@ -197,9 +196,37 @@ class UriToEntityConverterUnitTests {
return JMoleculesIdentifier.of(UUID.randomUUID());
}
@Value(staticConstructor = "of")
static class JMoleculesIdentifier implements Identifier {
UUID id;
static final class JMoleculesIdentifier implements Identifier {
private final UUID id;
private JMoleculesIdentifier(UUID id) {
this.id = id;
}
public static JMoleculesIdentifier of(UUID id) {
return new JMoleculesIdentifier(id);
}
public UUID getId() {
return this.id;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
JMoleculesIdentifier that = (JMoleculesIdentifier) o;
return ObjectUtils.nullSafeEquals(id, that.id);
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(id);
}
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.rest.core.domain;
import lombok.Value;
import java.util.UUID;
import org.springframework.data.annotation.Id;
@@ -25,9 +23,20 @@ import org.springframework.data.annotation.Reference;
/**
* @author Oliver Gierke
*/
@Value
class Order {
final class Order {
@Id UUID id = UUID.randomUUID();
@Reference Person creator;
@Id private final UUID id = UUID.randomUUID();
@Reference private final Person creator;
public Order(Person creator) {
this.creator = creator;
}
public UUID getId() {
return this.id;
}
public Person getCreator() {
return this.creator;
}
}

View File

@@ -15,10 +15,6 @@
*/
package org.springframework.data.rest.core.domain;
import lombok.AccessLevel;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -26,7 +22,7 @@ import java.util.List;
import java.util.UUID;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.annotation.Reference;
import org.springframework.data.rest.core.annotation.RestResource;
@@ -36,8 +32,6 @@ import org.springframework.data.rest.core.annotation.RestResource;
* @author Jon Brisbin
* @author Oliver Gierke
*/
@Data
@RequiredArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@PersistenceConstructor))
public class Person {
private final @Id UUID id;
@@ -51,8 +45,51 @@ public class Person {
private @RestResource(path = "father-mapped") @Reference Person father;
private Date created = Calendar.getInstance().getTime();
@PersistenceCreator
private Person(UUID id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public Person addSibling(Person p) {
siblings.add(p);
return this;
}
public UUID getId() {
return this.id;
}
public String getFirstName() {
return this.firstName;
}
public String getLastName() {
return this.lastName;
}
public List<Person> getSiblings() {
return this.siblings;
}
public Person getFather() {
return this.father;
}
public Date getCreated() {
return this.created;
}
public void setSiblings(List<Person> siblings) {
this.siblings = siblings;
}
public void setFather(Person father) {
this.father = father;
}
public void setCreated(Date created) {
this.created = created;
}
}

View File

@@ -15,9 +15,6 @@
*/
package org.springframework.data.rest.core.domain;
import lombok.Value;
import lombok.experimental.NonFinal;
import java.util.UUID;
import org.springframework.data.annotation.Id;
@@ -26,10 +23,25 @@ import org.springframework.data.annotation.Id;
* @author Jon Brisbin
* @author Oliver Gierke
*/
@NonFinal
@Value
public class Profile {
@Id UUID id = UUID.randomUUID();
String name, type;
@Id private final UUID id = UUID.randomUUID();
private final String name, type;
public Profile(String name, String type) {
this.name = name;
this.type = type;
}
public UUID getId() {
return this.id;
}
public String getName() {
return this.name;
}
public String getType() {
return this.type;
}
}

View File

@@ -17,8 +17,6 @@ package org.springframework.data.rest.core.support;
import static org.assertj.core.api.Assertions.*;
import lombok.Value;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
@@ -34,36 +32,31 @@ class ResourceStringUtilsTests {
@TestFactory
Stream<DynamicTest> shouldDetectTextPresence() {
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
assertThat(ResourceStringUtils.hasTextExceptSlash(it.getActual())).isEqualTo(it.hasText);
return DynamicTest.stream(fixtures(), Fixture::name, it -> {
assertThat(ResourceStringUtils.hasTextExceptSlash(it.actual())).isEqualTo(it.hasText);
});
}
@TestFactory
Stream<DynamicTest> shouldRemoveLeadingSlashIfAny() {
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
assertThat(ResourceStringUtils.removeLeadingSlash(it.getActual())).isEqualTo(it.getExpected());
return DynamicTest.stream(fixtures(), Fixture::name, it -> {
assertThat(ResourceStringUtils.removeLeadingSlash(it.actual())).isEqualTo(it.expected());
});
}
static Stream<Fixture> fixtures() {
return Stream.of(
Fixture.of("empty string has no text and should remain empty", "", "", false),
Fixture.of("blank string has no text and should remain as is", " ", " ", false),
Fixture.of("string made of only a leading slash has no text and should be returned empty", "/", "", false),
Fixture.of("blank string with only slashes has no text and should be returned as is", " / ", " / ",
return Stream.of(new Fixture("empty string has no text and should remain empty", "", "", false),
new Fixture("blank string has no text and should remain as is", " ", " ", false),
new Fixture("string made of only a leading slash has no text and should be returned empty", "/", "", false),
new Fixture("blank string with only slashes has no text and should be returned as is", " / ", " / ",
false),
Fixture.of("normal string has text and should be returned as such", "hello", "hello", true),
Fixture.of("normal string with leading slash has text and should be returned without leading slash", "/hello",
new Fixture("normal string has text and should be returned as such", "hello", "hello", true),
new Fixture("normal string with leading slash has text and should be returned without leading slash", "/hello",
"hello", true));
}
@Value(staticConstructor = "of")
static class Fixture {
String name, actual, expected;
boolean hasText;
record Fixture(String name, String actual, String expected, boolean hasText) {
}
}