easymodeling / easy-modeling

EasyModeling is a Java annotation processor that generates randomly populated objects for test use.
Apache License 2.0
43 stars 3 forks source link

Generate the builder when there is a nested class. #24

Open engtecmat opened 2 years ago

engtecmat commented 2 years ago

Describe the feature

Hi @zhezhangz,

I'm coming back, again. Thanks for your development of the invaluable features, such as 'list' and 'stream', and so on. However, I like them so much.

I'm writing to ask if it is possible for the builder can be generated even in a nested class. I thought you might think we seldom get this usage, but you know, we will.

Use Case

@Getter
@Setter
public class Order {
  private String orderNo;
  private List<OrderLine> lines;

  @Getter
  @Setter
  public static class OrderLine {
    private String name;
    private BigDecimal price;
  }
}
@Override
  protected void populate(OrderRequest model, ModelCache modelCache) {
    ReflectionUtil.setField(model, "com.project.template.api.OrderRequest#orderNo", new StringRandomizer(6, 20, 3).next());
    ReflectionUtil.setField(model, "com.project.template.api.OrderRequest#lines", new ListRandomizer<>(new CustomTypeRandomizer<>(new com.project.template.api.OrderRequest.OrderLineModeler(), modelCache), 1, 20).next());
  }
error: cannot find symbol
    ReflectionUtil.setField(model, "com.project.template.api.OrderRequest#lines", new ListRandomizer<>(new CustomTypeRandomizer<>(new com.project.template.api.OrderRequest.OrderLineModeler(), modelCache), 1, 20).next());
                                                                                                                                                                           ^
  symbol:   class OrderLineModeler
  location: class OrderRequest

Possible Solution / Additional Notes

No response

Acknowledgements

EasyModeling Version

0.1.3

zhezhangz commented 2 years ago

Hey Evan, Thank you so much for the feedback! The nested class as field types is an important feature that I have missed. I was thinking of handling that without changing the current framework too much, (while enjoying the summer with my family😜). However, I feel like it's not very easy to find a way for my poor design from the very beginning. Anyways, I will try to figure it out, or at least temporarily ignore the population of fields with inner classes as their types to avoid compiling errors.