Should the PODAM have been a bit more lenient with its definition of POJO?

27 views
Skip to first unread message

Sunil Veeramuthu

unread,
Apr 10, 2015, 5:09:31 PM4/10/15
to po...@googlegroups.com
Firstly, great library! I've been using it for a while now and it helps greatly with what I use it for.

On topic, I often deal with classes that are not the purest POJOs one would have seen, but very much require mock objects to be generated like a pure POJO would have. For instance, consider this class:

public class SpecialPojo {
  private static class Holder {
    private String holdingString;
    private long holdingLong;
  }
 
  private Holder myHolder;
 
  public SpecialPojo() {
    myHolder = new Holder();
  }
 
  public String getMyString() {
    return myHolder.holdingString;
  }
 
  public void setMyString(String myString) {
    myHolder.holdingString = myString;
  }
 
  public long getMyLong() {
    return myHolder.holdingLong;
  }
 
  public void setMyLong(long myLong) {
    myHolder.holdingLong = myLong;
  }
}

There's no reason to not call it a POJO, but PODAM won't map it b/c it's not got explicit state variables defined to match the setters/getters. If only PODAM didn't care about the instance variables and just tried to call the setters with the value to set, I'd have had an easier time mocking this class and generating an object with arbitrary values. Here's that part of PODAM (particularly the items in bold) I'm talking about:

    public static ClassInfo getClassInfo(Class<?> clazz, Set<Class<? extends Annotation>> excludeFieldAnnotations) {
        Set<String> classFields = getDeclaredInstanceFields(clazz, excludeFieldAnnotations);
        Set<Method> classSetters = getPojoSetters(clazz, classFields);
        return new ClassInfo(clazz, classFields, classSetters);
    }


Is this something the PODAM team can look into? Don't you think it'd add value to relax PODAM's definition of POJO a bit to accommodate such special cases?

Marco Tedone

unread,
Apr 10, 2015, 6:59:31 PM4/10/15
to po...@googlegroups.com
Hi Sunil, 

Thank you for using Podam. Our mantra is to serve the open-source community and your feedback means a lot to us. Yours is a good suggestion, so please raise an issue in GitHub and Daniil and I will discuss it for implementation.

Regards,

--
You received this message because you are subscribed to the Google Groups "PODAM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to podam+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sunil Veeramuthu

unread,
Apr 10, 2015, 8:02:06 PM4/10/15
to po...@googlegroups.com
Appreciate the quick response, Marco!

Here's this logged as an issue in github with the same example:
https://github.com/mtedone/podam/issues/86
Reply all
Reply to author
Forward
0 new messages