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:
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);
}
}
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:
If you’ve got lots of beans → bring in OpenPojo or Pojo Tester.
If it’s only a few → just test the properties you care about with AssertJ directly.
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?