java - Junit for MessageBoxProvider -


I have the code below

  if (MessageBoxProvider.questionMessageBox (shell, title, message )) {Overwrite to return (file); }  

How often I wanted to test (jeunit), how often the ordering method (file) method is called, I know that I can use the verification method to check My problem is MessageBoxProvider.questionMessageBox (shell

< P> User-interface code is mixed with it, then Unit Testing Business Logic becomes very complicated Ideally, Eine pattern, such as MVC or MVP, should be adopted, which completely blocks it.

If you can not go through that route or not, define an interface in which your message box Eg.

  Public Interface Message Provider {Boolean Pause Question (title, message); // ...}  

In your class constructor, this Accept the type of object and store it. Switch to, you can control the control can duplicate the object and can be tested by the use of user.

In your production code, use a solid implementation of this interface that will be used for your MessageBoxProvider methods.

Such an approach has the advantage of making your application more portable. If you want to issue a command-line version or a web-based version, you can change the way your concrete implementation is implemented.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -