Harsha D G
Harsha D G

Reputation: 25

unable to mock panache's persistAndFlush() due to lambda expressions

I'm using Quarkus with hibernate-panache-orm. Below is my sample code

Optional<OtherObject> opt = object.getList().stream().filter(predicate).findFirst();
if(opt.isPresent()){
    OtherObject obj = opt.get()
    obj.setVal("SomeVal");
    opt.persistAndFlush();
}

If I pass actual values for object from test class to main class, then opt.persistAndFlush() step will fail. Else not understanding how to mock .filter(predicate) step. Please help. Thanks in Advance

Upvotes: 0

Views: 384

Answers (1)

Schallabajzer
Schallabajzer

Reputation: 173

I think your intent here is to update the object. Currently you are trying to persist the Optional which is not an Entity and cannot become a Managed Entity.

In this case just change

opt.persistAndFlush();

to

obj.persistAndFlush();

Upvotes: 1

Related Questions