79753149

Date: 2025-09-02 06:41:43
Score: 1.5
Natty:
Report link

Looks like you’ve hit one of those spots where Hamcrest gives you a nice matcher out-of-the-box, but AssertJ doesn’t try to cover it. That’s why Co-Pilot spit out that huge reflection-based helper — technically correct, but way too much boilerplate for what you actually want.

If your goal is just “make sure getters and setters work”, you’ve got a couple of simpler options:

  1. Use a small bean testing library (e.g. OpenPojo or Pojo Tester).
    They integrate fine with JUnit 5 and keep your test short:

    import com.openpojo.validation.ValidatorBuilder;
    import com.openpojo.validation.test.impl.GetterTester;
    import com.openpojo.validation.test.impl.SetterTester;
    import org.junit.jupiter.api.Test;
    
    class GetServiceModelsByDistributionStatusResponseTest {
    
        @Test
        void shouldHaveValidGettersAndSetters() {
            var validator = ValidatorBuilder.create()
                .with(new GetterTester())
                .with(new SetterTester())
                .build();
    
            validator.validate(GetServiceModelsByDistributionStatusResponse.class);
        }
    }
    
    
  2. If it’s just one or two beans, don’t overthink it — write a tiny manual test:

    @Test
    void shouldSetAndGetStatus() {
        var bean = new GetServiceModelsByDistributionStatusResponse();
        bean.setStatus("OK");
        assertThat(bean.getStatus()).isEqualTo("OK");
    }
    
    

So in short:

Would you like me to show you a super minimal reflection-based AssertJ helper (like 20 lines) that you can reuse across all your beans, instead of the giant sample Co-Pilot gave you?

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: PixelCrafter