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

Unable to cover Getter and Setter of any Abstract class or derived class having abstract class extended #115

Open
jyotsnapa opened this issue May 3, 2018 · 6 comments

Comments

@jyotsnapa
Copy link

Hello Team,

Unable to cover Getter and Setter of any Abstract class or derived class having abstract class extended
Kindly help me out to cover it . Let me know how can cover Getter and setter of any Abstarct class. :)
Getting below error
com.openpojo.reflection.exception.ReflectionException: Failed to create instance for class [com.openpojo.reflection.impl.PojoClassImpl ....

Thanks
Jyotsna

@zygimantus
Copy link

I am having the same problem. The getters inside abstract class are somehow not detected and that results not in full code coverage.

@oshoukry
Copy link
Member

oshoukry commented May 25, 2018

@zygimantus Have you tried to test the abstract class itself?

@oshoukry
Copy link
Member

oshoukry commented May 25, 2018

@jyotsnapa Can you please send an example demonstrating the issue?
Also do you have ASM in your dependancies?

  <dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm</artifactId>
    <version>5.2</version>
  </dependency>

@zygimantus
Copy link

It worked! Just curious - why is it required to specify this ASM separately rather than including in OpenPojo library for convenience?

@presteus
Copy link

presteus commented Feb 4, 2020

I confirm @oshoukry comment, add this dependency help to resolve this issue.
To summary my context, I testing my existing code (jdk8) for jdk13 and this error happens.
I think this is due to the changes between 8 and 12.

@sabbott1877
Copy link

I'm having the same problem, but in JDK 8 (OpenJDK 1.8.0_212). Any help would be appreciated, or maybe it can help get to the bottom of a problem. Thanks!

I'm using:

<dependency>
    <groupId>com.openpojo</groupId>
    <artifactId>openpojo</artifactId>
    <version>0.8.13</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm</artifactId>
    <version>8.0.1</version>
</dependency>
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>RELEASE</version>
    <scope>test</scope>
</dependency>

And the test code:

package org.openpojo;

import com.openpojo.reflection.impl.PojoClassFactory;
import com.openpojo.validation.ValidatorBuilder;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
import org.testng.annotations.Test;

public class OPJFailure {

  @Test
  public void testValidateAccessors_Pass() throws Exception {
    ValidatorBuilder.create()
        .with(new GetterTester())
        .with(new SetterTester())
        .build().validate(PojoClassFactory.getPojoClass(PassClassAbstract.class));
  }

  @Test(expectedExceptions = AssertionError.class, expectedExceptionsMessageRegExp = "Getter returned non equal value for field.*")
  public void testValidateAccessorsAbstract_Fail() throws Exception {
    ValidatorBuilder.create()
        .with(new GetterTester())
        .with(new SetterTester())
        .build().validate(PojoClassFactory.getPojoClass(FailClassAbstract.class));
  }

  private static abstract class FailClassAbstract {
    private int test;

    public int getTest() {
      return -1;
    }

    public void setTest(int test) {
      this.test = 0;
    }

    public abstract int doesSomething();
  }


  private static abstract class PassClassAbstract {
    private int test;

    public int getTest() {
      return test;
    }

    public void setTest(int test) {
      this.test = test;
    }

    public abstract int doesSomething();

  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants