0

BindUtils.postNotifyChange() test junit with mockito is possible ?

asked 2023-04-03 19:54:00 +0800

ypaz gravatar image ypaz
1

Hello!

I have a question over the junit test.

We could test this line BindUtils.postNotifyChange(null, null, this, ACTIVE_STEP); with junit.

I use Junit5 and I'm doing a test for my stepbar component and i have to test the next step but i don't know how to do it because I have that to notify the change :(

I'm using this action BindUtils.postNotifyChange(...); to notify the change to the component.

Do you have any tips to mock this action (BindUtils.postNotifyChange) ?

I have an error in the console like this when I run the test:

java.lang.IllegalStateException: Not in an execution    at org.zkoss.zk.ui.event.impl.EventQueueProviderImpl.lookup(EventQueueProviderImpl.java:67)     at org.zkoss.zk.ui.event.EventQueues.lookup(EventQueues.java:130)   at org.zkoss.bind.BindUtils.postNotifyChange(BindUtils.java:69)     at ch.unil.escan.viewModel.StepBarModel.navigateTo(StepBarModel.java:42)    at ch.unil.escan.viewModel.StepBarModel.nextToNotify(StepBarModel.java:34)  at ch.unil.escan.viewModel.ScanViewModel.validOption(ScanViewModel.java:273)    at ch.unil.escan.viewModel.ScanViewModelTest.testValidOption(ScanViewModelTest.java:78)     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

Thank you.

Yvan

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-24 11:17:53 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

if you test with JUnit, there is no ZK Execution object existing in the context, it's a class that wraps a HttpServletRequest. Since there is no browser request, that's why you see java.lang.IllegalStateException: Not in an execution

ZATS already mimics the whole environment for you and provides API to assert a component's state, please try to run junit with it. If you still have problems, please attach the related code.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2023-04-03 19:54:00 +0800

Seen: 5 times

Last updated: Apr 24 '23

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More