Skip to content

Commit 43f3693

Browse files
Add Lombok dependency and annotation processor configuration to xapi-model-spring-boot-starter
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
1 parent f52df46 commit 43f3693

3 files changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Suppress code coverage on Lombok annotations
2+
lombok.addLombokGeneratedAnnotation = true
3+
lombok.builder.className = Builder
4+
lombok.anyConstructor.addConstructorProperties = true

xapi-model-spring-boot-starter/pom.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@
3939
<groupId>dev.learning.xapi</groupId>
4040
<artifactId>xapi-model</artifactId>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.projectlombok</groupId>
44+
<artifactId>lombok</artifactId>
45+
<optional>true</optional>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-starter-test</artifactId>
50+
<scope>test</scope>
51+
</dependency>
4252
</dependencies>
4353

4454
<build>
@@ -47,6 +57,19 @@
4757
<groupId>org.jacoco</groupId>
4858
<artifactId>jacoco-maven-plugin</artifactId>
4959
</plugin>
60+
<plugin>
61+
<groupId>org.apache.maven.plugins</groupId>
62+
<artifactId>maven-compiler-plugin</artifactId>
63+
<configuration>
64+
<annotationProcessorPaths>
65+
<path>
66+
<groupId>org.projectlombok</groupId>
67+
<artifactId>lombok</artifactId>
68+
<version>${lombok.version}</version>
69+
</path>
70+
</annotationProcessorPaths>
71+
</configuration>
72+
</plugin>
5073
</plugins>
5174
</build>
5275

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright 2016-2025 Berry Cloud Ltd. All rights reserved.
3+
*/
4+
5+
package dev.learning.xapi.autoconfigure.model;
6+
7+
import static org.hamcrest.MatcherAssert.assertThat;
8+
import static org.hamcrest.Matchers.is;
9+
import static org.hamcrest.Matchers.notNullValue;
10+
11+
import lombok.Builder;
12+
import lombok.Getter;
13+
import lombok.Setter;
14+
import lombok.Value;
15+
import org.junit.jupiter.api.DisplayName;
16+
import org.junit.jupiter.api.Test;
17+
18+
/**
19+
* Tests that Lombok annotation processing works correctly with xapi-model-spring-boot-starter. This
20+
* test ensures that third-party projects can use Lombok annotations without additional
21+
* configuration.
22+
*
23+
* @author GitHub Copilot
24+
*/
25+
class LombokProcessingTests {
26+
27+
/**
28+
* Test class using Lombok @Getter and @Setter annotations. This simulates the Subscription class
29+
* mentioned in the issue.
30+
*/
31+
@Getter
32+
@Setter
33+
static class TestSubscription {
34+
private String id;
35+
private String topic;
36+
private boolean active;
37+
}
38+
39+
/**
40+
* Test class using Lombok @Builder annotation. This simulates the SubscriptionProperties class
41+
* mentioned in the issue.
42+
*/
43+
@Builder
44+
@Getter
45+
static class TestSubscriptionProperties {
46+
private String endpoint;
47+
private int maxRetries;
48+
private long timeout;
49+
}
50+
51+
/** Test class using Lombok @Value annotation for immutability. */
52+
@Value
53+
@Builder
54+
static class TestImmutableSubscription {
55+
String id;
56+
String topic;
57+
boolean active;
58+
}
59+
60+
@Test
61+
@DisplayName("When Using Getter And Setter Then Lombok Processing Works")
62+
void testGetterSetterProcessing() {
63+
// Given
64+
TestSubscription subscription = new TestSubscription();
65+
66+
// When
67+
subscription.setId("sub-123");
68+
subscription.setTopic("xapi-events");
69+
subscription.setActive(true);
70+
71+
// Then
72+
assertThat(subscription.getId(), is("sub-123"));
73+
assertThat(subscription.getTopic(), is("xapi-events"));
74+
assertThat(subscription.isActive(), is(true));
75+
}
76+
77+
@Test
78+
@DisplayName("When Using Builder Then Lombok Processing Works")
79+
void testBuilderProcessing() {
80+
// When
81+
TestSubscriptionProperties properties =
82+
TestSubscriptionProperties.builder()
83+
.endpoint("https://example.com/webhook")
84+
.maxRetries(3)
85+
.timeout(5000L)
86+
.build();
87+
88+
// Then
89+
assertThat(properties, is(notNullValue()));
90+
assertThat(properties.getEndpoint(), is("https://example.com/webhook"));
91+
assertThat(properties.getMaxRetries(), is(3));
92+
assertThat(properties.getTimeout(), is(5000L));
93+
}
94+
95+
@Test
96+
@DisplayName("When Using Value Then Lombok Processing Works")
97+
void testValueProcessing() {
98+
// When
99+
TestImmutableSubscription subscription =
100+
TestImmutableSubscription.builder()
101+
.id("sub-456")
102+
.topic("xapi-statements")
103+
.active(false)
104+
.build();
105+
106+
// Then
107+
assertThat(subscription, is(notNullValue()));
108+
assertThat(subscription.getId(), is("sub-456"));
109+
assertThat(subscription.getTopic(), is("xapi-statements"));
110+
assertThat(subscription.isActive(), is(false));
111+
}
112+
}

0 commit comments

Comments
 (0)