mtedone / podam

PODAM - POjo DAta Mocker
https://mtedone.github.io/podam
MIT License
326 stars 749 forks source link

Complete PodamAnnotation Target value to allow lombok full usage #321

Closed liam-kincaid closed 10 months ago

liam-kincaid commented 10 months ago

May you change the PodamAnnotation from: ` package uk.co.jemos.podam.common;

    import java.lang.annotation.Documented;
    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;

    /**
     * Annotation to mark PODAM annotations.
     * 
     * 
     * @author maxdidato
     * 
     */
    @Documented
    @Target({ElementType.ANNOTATION_TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface PodamAnnotation {
    }

`

to: ` package uk.co.jemos.podam.common;

    import java.lang.annotation.Documented;
    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;

    /**
     * Annotation to mark PODAM annotations.
     * 
     * 
     * @author maxdidato
     * 
     */
    @Documented
    @Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    public @interface PodamAnnotation {
    }

` to be use with "lombok". The addition of ElementType.METHOD allow the use on parameter "onMethod_" in lombok initialisation.

daivanov commented 10 months ago

Hi,

PodamAnnotation is an annotation to annotate other annotations. It is not supposed to be applied to the methods. So @Target is correct.

Thanks, Daniil

liam-kincaid commented 10 months ago

In this case, you could change all over annotation, like PodamIntValue, etc Is-it possible ?

daivanov commented 10 months ago

In my understanding you should be doing something like this with lombok

import lombok.Getter;
import lombok.Setter;
import uk.co.jemos.podam.common.PodamIntValue;

public class Example {

  @Getter @Setter @PodamIntValue(minValue = 0, maxValue = 10) private int value;

}

I'm not sure why there is a need for on onMethod_ parameter.

Thanks, Daniil

liam-kincaid commented 10 months ago

Ok, I explain. I use a custom build method in a builder with hibernate validation. As you guest, I use @With. Read a sample User.tar.gz

This illustrate my purpose

daivanov commented 10 months ago

You have class User with a constructor

User(final UserBuilder builder)

And class UserBuilder with a constructor public UserBuilder(@NotNull final User user)

This cannot work. But again I don't see a reason why you try to add podam annotations to a method.

Thanks, Daniil

liam-kincaid commented 10 months ago

I use delombok and I saw my bad. I want to have this: @With(onParam_={ @PodamIntValue(minValue = 1) }) to generate this: public UserBuilder withId(@PodamIntValue(minValue = 1) Long _id) { You could close this Issue. Sorry and thanks you again