Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor basic types with several corrections #48

Merged
merged 4 commits into from
Dec 11, 2023

Conversation

tfdsimoes
Copy link
Collaborator

@tfdsimoes tfdsimoes commented Dec 6, 2023

There was several errors in basic types and unnecessary code in the generation.

Giving the class

@PactDslBodyBuilder
@Data
public class DemoClass {

    @Example("123")
    private int anInt1;

    private int anInt2;

    @Example("123")
    private Integer anInteger1;

    private Integer anInteger2;

    @Example("123")
    private BigInteger aBigInteger1;

    private BigInteger aBigInteger2;

    @Example("12")
    private short aShort1;

    private short aShort2;

    @Example("12")
    private Short aShort3;

    private Short aShort4;

    @Example("12")
    private byte aByte1;

    private byte aByte2;

    @Example("12")
    private Byte aByte3;

    private Byte aByte4;

    @Example("1234")
    private long aLong1;

    private long aLong2;

    @Example("1234")
    private Long aLong3;

    private Long aLong4;

    @Example("a")
    private char aChar1;

    private char aChar2;

    @Example("a")
    private Character aCharacter1;

    private Character aCharacter2;

    @Example("abcd")
    private String aString1;

    private String aString2;

    @Example("1.23")
    private float aFloat1;

    private float aFloat2;

    @Example("1.23")
    private Float aFloat3;

    private Float aFloat4;

    @Example("1.23")
    private double aDouble1;

    private double aDouble2;

    @Example("1.23")
    private Double aDouble3;

    private Double aDouble4;

    @Example("1.23")
    private BigDecimal aBigDecimal1;

    private BigDecimal aBigDecimal2;

    @Example("true")
    private boolean aBoolean1;

    private boolean aBoolean2;

    @Example("true")
    private Boolean aBoolean3;

    private Boolean aBoolean4;
}

It generates

public class DemoClassBuilder {
        int anInt1 = 123;
        int anInt2 = -1722414540;
        int anInteger1 = 123;
        int anInteger2 = -1433472607;
        BigInteger aBigInteger1 = new BigInteger("123");
        BigInteger aBigInteger2 = new BigInteger("475840479");
        short aShort1 = 12;
        short aShort2 = -21381;
        short aShort3 = 12;
        short aShort4 = -2404;
        byte aByte1 = 12;
        byte aByte2 = -9;
        byte aByte3 = 12;
        byte aByte4 = 94;
        long aLong1 = 1234L;
        long aLong2 = 4874615238199996744L;
        long aLong3 = 1234L;
        long aLong4 = 7019723070688293282L;
      String aChar1 = "a";
      String aChar2 = "D";
      String aCharacter1 = "a";
      String aCharacter2 = "Y";
      String aString1 = "abcd";
      String aString2 = "B6dECbd";
        float aFloat1 = 1.23F;
        float aFloat2 = 7.61030512111253E37F;
        float aFloat3 = 1.23F;
        float aFloat4 = 2.7996246996530064E38F;
        double aDouble1 = 1.23D;
        double aDouble2 = 1.6697744108023105E307D;
        double aDouble3 = 1.23D;
        double aDouble4 = 1.4821891169488752E308D;
        BigDecimal aBigDecimal1 = new BigDecimal("1.23");
        BigDecimal aBigDecimal2 = new BigDecimal("3.322193950059484E307");
      boolean aBoolean1 = true;
      boolean aBoolean2 = false;
      boolean aBoolean3 = true;
      boolean aBoolean4 = false;

    public DemoClassBuilder setAnInt1(final int anInt1) {
    this.anInt1 = anInt1;
    return this;
  }
    public DemoClassBuilder setAnInt2(final int anInt2) {
    this.anInt2 = anInt2;
    return this;
  }
    public DemoClassBuilder setAnInteger1(final int anInteger1) {
    this.anInteger1 = anInteger1;
    return this;
  }
    public DemoClassBuilder setAnInteger2(final int anInteger2) {
    this.anInteger2 = anInteger2;
    return this;
  }
    public DemoClassBuilder setABigInteger1(final BigInteger aBigInteger1) {
    this.aBigInteger1 = aBigInteger1;
    return this;
  }
    public DemoClassBuilder setABigInteger2(final BigInteger aBigInteger2) {
    this.aBigInteger2 = aBigInteger2;
    return this;
  }
    public DemoClassBuilder setAShort1(final short aShort1) {
    this.aShort1 = aShort1;
    return this;
  }
    public DemoClassBuilder setAShort2(final short aShort2) {
    this.aShort2 = aShort2;
    return this;
  }
    public DemoClassBuilder setAShort3(final short aShort3) {
    this.aShort3 = aShort3;
    return this;
  }
    public DemoClassBuilder setAShort4(final short aShort4) {
    this.aShort4 = aShort4;
    return this;
  }
    public DemoClassBuilder setAByte1(final byte aByte1) {
    this.aByte1 = aByte1;
    return this;
  }
    public DemoClassBuilder setAByte2(final byte aByte2) {
    this.aByte2 = aByte2;
    return this;
  }
    public DemoClassBuilder setAByte3(final byte aByte3) {
    this.aByte3 = aByte3;
    return this;
  }
    public DemoClassBuilder setAByte4(final byte aByte4) {
    this.aByte4 = aByte4;
    return this;
  }
    public DemoClassBuilder setALong1(final long aLong1) {
    this.aLong1 = aLong1;
    return this;
  }
    public DemoClassBuilder setALong2(final long aLong2) {
    this.aLong2 = aLong2;
    return this;
  }
    public DemoClassBuilder setALong3(final long aLong3) {
    this.aLong3 = aLong3;
    return this;
  }
    public DemoClassBuilder setALong4(final long aLong4) {
    this.aLong4 = aLong4;
    return this;
  }
      public DemoClassBuilder setAChar1(final String aChar1) {
    this.aChar1 = aChar1;
    return this;
  }
      public DemoClassBuilder setAChar2(final String aChar2) {
    this.aChar2 = aChar2;
    return this;
  }
      public DemoClassBuilder setACharacter1(final String aCharacter1) {
    this.aCharacter1 = aCharacter1;
    return this;
  }
      public DemoClassBuilder setACharacter2(final String aCharacter2) {
    this.aCharacter2 = aCharacter2;
    return this;
  }
    public DemoClassBuilder setAString1(final String aString1) {
    this.aString1 = aString1;
    return this;
  }
    public DemoClassBuilder setAString2(final String aString2) {
    this.aString2 = aString2;
    return this;
  }
    public DemoClassBuilder setAFloat1(final float aFloat1) {
    this.aFloat1 = aFloat1;
    return this;
  }
    public DemoClassBuilder setAFloat2(final float aFloat2) {
    this.aFloat2 = aFloat2;
    return this;
  }
    public DemoClassBuilder setAFloat3(final float aFloat3) {
    this.aFloat3 = aFloat3;
    return this;
  }
    public DemoClassBuilder setAFloat4(final float aFloat4) {
    this.aFloat4 = aFloat4;
    return this;
  }
    public DemoClassBuilder setADouble1(final double aDouble1) {
    this.aDouble1 = aDouble1;
    return this;
  }
    public DemoClassBuilder setADouble2(final double aDouble2) {
    this.aDouble2 = aDouble2;
    return this;
  }
    public DemoClassBuilder setADouble3(final double aDouble3) {
    this.aDouble3 = aDouble3;
    return this;
  }
    public DemoClassBuilder setADouble4(final double aDouble4) {
    this.aDouble4 = aDouble4;
    return this;
  }
    public DemoClassBuilder setABigDecimal1(final BigDecimal aBigDecimal1) {
    this.aBigDecimal1 = aBigDecimal1;
    return this;
  }
    public DemoClassBuilder setABigDecimal2(final BigDecimal aBigDecimal2) {
    this.aBigDecimal2 = aBigDecimal2;
    return this;
  }
    public DemoClassBuilder setABoolean1(final boolean aBoolean1) {
    this.aBoolean1 = aBoolean1;
    return this;
  }
    public DemoClassBuilder setABoolean2(final boolean aBoolean2) {
    this.aBoolean2 = aBoolean2;
    return this;
  }
    public DemoClassBuilder setABoolean3(final boolean aBoolean3) {
    this.aBoolean3 = aBoolean3;
    return this;
  }
    public DemoClassBuilder setABoolean4(final boolean aBoolean4) {
    this.aBoolean4 = aBoolean4;
    return this;
  }

    public DslPart build() {
        PactDslJsonBody pactDslJsonBody = new PactDslJsonBody();
          if (Objects.nonNull(anInt1)) {
            pactDslJsonBody.integerType("anInt1", anInt1);
          }
          if (Objects.nonNull(anInt2)) {
            pactDslJsonBody.integerType("anInt2", anInt2);
          }
          if (Objects.nonNull(anInteger1)) {
            pactDslJsonBody.integerType("anInteger1", anInteger1);
          }
          if (Objects.nonNull(anInteger2)) {
            pactDslJsonBody.integerType("anInteger2", anInteger2);
          }
          if (Objects.nonNull(aBigInteger1)) {
            pactDslJsonBody.integerType("aBigInteger1", aBigInteger1.intValue());
          }
          if (Objects.nonNull(aBigInteger2)) {
            pactDslJsonBody.integerType("aBigInteger2", aBigInteger2.intValue());
          }
          if (Objects.nonNull(aShort1)) {
            pactDslJsonBody.integerType("aShort1", (int) aShort1);
          }
          if (Objects.nonNull(aShort2)) {
            pactDslJsonBody.integerType("aShort2", (int) aShort2);
          }
          if (Objects.nonNull(aShort3)) {
            pactDslJsonBody.integerType("aShort3", (int) aShort3);
          }
          if (Objects.nonNull(aShort4)) {
            pactDslJsonBody.integerType("aShort4", (int) aShort4);
          }
          if (Objects.nonNull(aByte1)) {
            pactDslJsonBody.integerType("aByte1", (int) aByte1);
          }
          if (Objects.nonNull(aByte2)) {
            pactDslJsonBody.integerType("aByte2", (int) aByte2);
          }
          if (Objects.nonNull(aByte3)) {
            pactDslJsonBody.integerType("aByte3", (int) aByte3);
          }
          if (Objects.nonNull(aByte4)) {
            pactDslJsonBody.integerType("aByte4", (int) aByte4);
          }
          if (Objects.nonNull(aLong1)) {
            pactDslJsonBody.integerType("aLong1", aLong1);
          }
          if (Objects.nonNull(aLong2)) {
            pactDslJsonBody.integerType("aLong2", aLong2);
          }
          if (Objects.nonNull(aLong3)) {
            pactDslJsonBody.integerType("aLong3", aLong3);
          }
          if (Objects.nonNull(aLong4)) {
            pactDslJsonBody.integerType("aLong4", aLong4);
          }
          if (Objects.nonNull(aChar1)) {
            pactDslJsonBody.stringType("aChar1", aChar1);
          }
          if (Objects.nonNull(aChar2)) {
            pactDslJsonBody.stringType("aChar2", aChar2);
          }
          if (Objects.nonNull(aCharacter1)) {
            pactDslJsonBody.stringType("aCharacter1", aCharacter1);
          }
          if (Objects.nonNull(aCharacter2)) {
            pactDslJsonBody.stringType("aCharacter2", aCharacter2);
          }
          if (Objects.nonNull(aString1)) {
            pactDslJsonBody.stringType("aString1", aString1);
          }
          if (Objects.nonNull(aString2)) {
            pactDslJsonBody.stringType("aString2", aString2);
          }
          if (Objects.nonNull(aFloat1)) {
            pactDslJsonBody.decimalType("aFloat1", (double) aFloat1);
          }
          if (Objects.nonNull(aFloat2)) {
            pactDslJsonBody.decimalType("aFloat2", (double) aFloat2);
          }
          if (Objects.nonNull(aFloat3)) {
            pactDslJsonBody.decimalType("aFloat3", (double) aFloat3);
          }
          if (Objects.nonNull(aFloat4)) {
            pactDslJsonBody.decimalType("aFloat4", (double) aFloat4);
          }
          if (Objects.nonNull(aDouble1)) {
            pactDslJsonBody.decimalType("aDouble1", aDouble1);
          }
          if (Objects.nonNull(aDouble2)) {
            pactDslJsonBody.decimalType("aDouble2", aDouble2);
          }
          if (Objects.nonNull(aDouble3)) {
            pactDslJsonBody.decimalType("aDouble3", aDouble3);
          }
          if (Objects.nonNull(aDouble4)) {
            pactDslJsonBody.decimalType("aDouble4", aDouble4);
          }
          if (Objects.nonNull(aBigDecimal1)) {
            pactDslJsonBody.decimalType("aBigDecimal1", aBigDecimal1);
          }
          if (Objects.nonNull(aBigDecimal2)) {
            pactDslJsonBody.decimalType("aBigDecimal2", aBigDecimal2);
          }
          if (Objects.nonNull(aBoolean1)) {
            pactDslJsonBody.booleanType("aBoolean1", aBoolean1);
          }
          if (Objects.nonNull(aBoolean2)) {
            pactDslJsonBody.booleanType("aBoolean2", aBoolean2);
          }
          if (Objects.nonNull(aBoolean3)) {
            pactDslJsonBody.booleanType("aBoolean3", aBoolean3);
          }
          if (Objects.nonNull(aBoolean4)) {
            pactDslJsonBody.booleanType("aBoolean4", aBoolean4);
          }


        return pactDslJsonBody;
    }

    public DemoClass buildExpectedInstance() {
        DemoClass object = new DemoClass();
          object.setAnInt1(this.anInt1);
          object.setAnInt2(this.anInt2);
          object.setAnInteger1(this.anInteger1);
          object.setAnInteger2(this.anInteger2);
          object.setABigInteger1(this.aBigInteger1);
          object.setABigInteger2(this.aBigInteger2);
          object.setAShort1(this.aShort1);
          object.setAShort2(this.aShort2);
          object.setAShort3(this.aShort3);
          object.setAShort4(this.aShort4);
          object.setAByte1(this.aByte1);
          object.setAByte2(this.aByte2);
          object.setAByte3(this.aByte3);
          object.setAByte4(this.aByte4);
          object.setALong1(this.aLong1);
          object.setALong2(this.aLong2);
          object.setALong3(this.aLong3);
          object.setALong4(this.aLong4);
          object.setAChar1(this.aChar1.charAt(0));
          object.setAChar2(this.aChar2.charAt(0));
          object.setACharacter1(this.aCharacter1.charAt(0));
          object.setACharacter2(this.aCharacter2.charAt(0));
          object.setAString1(this.aString1);
          object.setAString2(this.aString2);
          object.setAFloat1(this.aFloat1);
          object.setAFloat2(this.aFloat2);
          object.setAFloat3(this.aFloat3);
          object.setAFloat4(this.aFloat4);
          object.setADouble1(this.aDouble1);
          object.setADouble2(this.aDouble2);
          object.setADouble3(this.aDouble3);
          object.setADouble4(this.aDouble4);
          object.setABigDecimal1(this.aBigDecimal1);
          object.setABigDecimal2(this.aBigDecimal2);
          object.setABoolean1(this.aBoolean1);
          object.setABoolean2(this.aBoolean2);
          object.setABoolean3(this.aBoolean3);
          object.setABoolean4(this.aBoolean4);
        return object;
    }

    private static void applyCustomModifiers(PactDslJsonBody pactDslJsonBody) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    }

}

@tfdsimoes tfdsimoes added the bug Something isn't working label Dec 6, 2023
Copy link

github-actions bot commented Dec 6, 2023

This pull request hasn't been labeled as release nor documentation. Please ensure this is intentional before merging.

@tfdsimoes tfdsimoes added the release Trigger a release label Dec 6, 2023
@jemacineiras
Copy link
Contributor

Is needed to change the Readme?

@jemacineiras jemacineiras merged commit 310ca70 into main Dec 11, 2023
11 checks passed
@jemacineiras jemacineiras deleted the refactor/refactor_basic_types branch December 11, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working release Trigger a release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants