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

javax.validation.ConstraintViolationException: may not be null for a mocked object in TestNG test #234

Open
sandeepkhanzode opened this issue Oct 20, 2016 · 3 comments

Comments

@sandeepkhanzode
Copy link

sandeepkhanzode commented Oct 20, 2016

I started to integrate jcabi-aspects into an already built Spring application with JSR-303 Hibernate-Validator based annotations. The @loggable seems to work displaying the time, etc. But the existing TestNG test cases fail at weird code locations. Weird since the @NotNull annotation should not fail because a properly mocked instance of the argument is being passed in the test. I can verify this by removing the ajc plugin from the build->plugins in pom.xml and running the test. Of course, everything works properly.

I am not sure why the MethodValidator of jcabi is being invoked at the stack trace below. Please let me know what I should check. Thanks!!

I am using jcabi-aspects v.0.22.5 and aspectjrt v.1.5.4

**javax.validation.ConstraintViolationException: may not be null**
    at com.jcabi.aspects.aj.MethodValidator.checkForViolations(MethodValidator.java:189)
    at com.jcabi.aspects.aj.MethodValidator.validateMethod(MethodValidator.java:154)
    at com.jcabi.aspects.aj.MethodValidator.beforeMethod(MethodValidator.java:87)
    at ...

I also see this in the logs for init JMockit mocks ...

---

FAILED CONFIGURATION: @BeforeMethod xxx
org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Misplaced argument matcher detected here:

-> at ....
You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
    when(mock.get(anyInt())).thenReturn(null);
    doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
    verify(mock).someMethod(contains("foo"))

Also, this error might show up because you use argument matchers with methods that cannot be mocked.
Following methods _cannot_ be stubbed/verified: final/private/equals()/hashCode().
Mocking methods declared on non-public parent classes is not supported.
@dmarkov
Copy link

dmarkov commented Oct 28, 2016

@yegor256 please pay attention to this issue (par.21)

@yegor256
Copy link
Member

@sandeepkhanzode well, if you pass NULL and there is @NotNull annotation, you get an exception. That's what jcabi-aspects is doing.

@naveensharma18
Copy link

naveensharma18 commented Sep 24, 2018

I'm not sending null, still getting same exception(may not be empty). Below is the method argument

@notblank @FormParam(MOBILE_PHONE_NUMBER) String mobilePhoneNumber

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

4 participants