|
| 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