Testing when Observable notifies Observers and calls update() method in Spock?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Testing when Observable notifies Observers and calls update() method in Spock?

Steve Storck
Hello.  The class under test is an extension of Observable.  When something happens, I call notifyObservers(withUpdatedData).  In my test method, I have tried a few things:
  • I have created a Mock(Observer) object and called addObserver(mock)
    • I have an "updated" flag in the Observable extension, and I wait for that to become true.
    • I then check for an interaction with the mock that indicates that the update(Observable o, Object stuff) was called.
    • Result: the test results indicate that the method was never called.  There are no "similar" invocations reported.
  • I have used BlockingVariable instances (ten second timeout) in conjunction with declaring a new Observable implementation in the setup block
    • I add this observer by calling observable.addObserver(observerInlineImpl)
    • The update method sets this variable
    • I attempt to evaluate this BlockingVariable in the then: block
    • Result: The test times out due to the Blocking Variable not being set.
  • I have created an Observer implementation in the setup block, along with a CountdownLatch. 
    • I add a method in the Observer called waitUntilUpdateIsCalled, and the body of that method just calls latch.await()
    • The update method performs latch.countdown() and then sets a variable
    • In the then: block, I inspect the variable
    • Result: the test infinitely hangs waiting for the latch

What am I doing wrong?  I am at home and I don't have access to the repository at the moment, but I can post code tomorrow if this info isn't enough.  Thanks in advance for any help anyone can provide.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Testing when Observable notifies Observers and calls update() method in Spock?

Steve Storck
Update: I was not calling setChanged() on the Observable.  After adding that, everything is fine.

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.