• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to mock the Swing thread?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to mock the swing thread in my junit test so that I can easy unit tests for GUI. Could you please let me whether it is possible and how?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what you mean by "mock the Swing thread". Could you please elaborate? What kind of tests do you want to write?
 
Ahetuki Neti
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my GUI code, I have two types of threads functioning:
1. Java threads in the model fetching data from the server. These threads help in doing some background processing (lazy loading).
2. Swing threads (I dont have any control/reference to it) that function beyond my control in the events like "fireTableRowChanged.." etc.

The first type of threads can be easily controlled by me because I have references to them (I use a factory to generate them and I can easily mock them by mocking the factory). But the later ones are beyond my control and these are the ones which I need to control. I need to mock them so that all the threads in my junit tests become synchronous!
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still wonder what kinds of tests you try to write. I've written a whole book chapter about writing unit tests for Swing components, and read a whole lot of other ones, and never came across the desire to synchronize some threads.

So could you please elaborate on why you think you need to?
 
Ahetuki Neti
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very simple! Instead of having different threads running parallely I want to force the usage of a single thread (mock) through all business classes.
Let me give an example:
In my unit test I create a row in an empty table -> event is fired -> Somehow the event handling (swing thread) is slower than the next step in my test case: Verifying a value in the created row -> I get ArrayOutOfBoundException because the row is not yet created!
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the code? I don't remember any such case in my practice and would like to try your code at home...
 
reply
    Bookmark Topic Watch Topic
  • New Topic