0

I’ve created the following captor:

public class CompanyOwnerMatcher extends ArgumentMatcher<CompanyOwner> {

    private String uuid;

    CompanyOwnerMatcher(String uuid) {
        this.uuid = uuid;
    }

    @Override
    public boolean matches(Object arg) {
        if (!(arg instanceof CompanyOwner)) return false;
        CompanyOwner owner = (CompanyOwner) arg;
        return Objects.equals(uuid, owner.getUuid());
    }
}

I get an exception in this code:

Mockito.verify(payInApi).submit(eq(1L), argThat(new CompanyOwnerMatcher(expectedOwnerUuid)));

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:148)
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:266)

CompanyOwner is managed by hibernate. It’s weird, but after I catch a CompanyOwner, I can’t get any field values on it because I get LazyInitializationException, even on fields that are not marked as Lazy.

Would appreciate any help with regards to this problem.

Thanks!