I have this Renew class:
@Getter
@Setter
@ToString
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@Builder(toBuilder = true)
@EqualsAndHashCode
public class A {
private ItemInfo itemInfo;
public boolean hasErrors() {
return (itemInfo!= null && itemInfo.hasErrors());
}
}
@Getter
@Setter
@ToString
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@Builder(toBuilder = true)
@EqualsAndHashCode
public class B extends A {
private Price bestPrice;
private Price alternativePrice;
}
My test class has:
mocked =
B.builder()
.itemInfo(null)
.bestPrice(null)
.alternativePrice(null)
.build();
I get an error saying Create method 'itemInfo' in 'BBuilder in B'
. I thought that given B extends A, B should contain all that A has. How do I resolve this?
You could try out @SuperBuilder
(experimental)
https://projectlombok.org/features/experimental/SuperBuilder