Takuya Ono
takuy****@users*****
2007年 8月 16日 (木) 04:17:09 JST
Index: BetaProject/test/org/jent/checksmtp/MessageDialogUITest.java diff -u /dev/null BetaProject/test/org/jent/checksmtp/MessageDialogUITest.java:1.1 --- /dev/null Thu Aug 16 04:17:09 2007 +++ BetaProject/test/org/jent/checksmtp/MessageDialogUITest.java Thu Aug 16 04:17:08 2007 @@ -0,0 +1,134 @@ +/* + * MessageDialogUITest.java + * JUnit based test + * + * Created on 2007/08/14, 15:22 + */ + +package org.jent.checksmtp; + +import junit.framework.*; +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * + * @author tkyn + */ +public class MessageDialogUITest extends TestCase { + + public MessageDialogUITest(String testName) { + super(testName); + } + + //Detail Open/Close ããããã®æã®ãã¤ã¢ãã°ã®å¤§ãã + static int openUiHeight = -1; + static int closeUiHeight = -1; + + private void setupStaticVar() { + if ( openUiHeight > 0 ) { //æ£æ°ãå ¥ã£ã¦ãããæ¢ã«è¨å®æ¸ã¿ã ã¨æãã + return; + } + + //ã¾ãã¯ãDetail Open/Closeæã®ãã¤ã¢ãã°ã®é«ããä¿åãã¦ããã + //ãã®ãã¹ããä¸çªæåã«å®è¡ããå¿ è¦ãããã + Exception ex = new Exception(); + MessageDialogUI openUi = new MessageDialogUI("Detail Open/Close test", ex, 0); + openUi.setDetailOpen(true); + + openUi.setDetailOpen(false); //This method effort for Class variable. + MessageDialogUI closeUi = new MessageDialogUI("Detail Open/Close test", ex, 0); + + openUiHeight = openUi.getHeight(); + closeUiHeight = closeUi.getHeight(); + + openUi.dispose(); + closeUi.dispose(); + + openUi.setDetailOpen(true); + } + + protected void setUp() throws Exception { + System.out.println("setup()"); + } + + protected void tearDown() throws Exception { + } + + private void sleep(long millsec) { + try { + Thread.sleep(millsec); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + } + + private void wait(MessageDialogUI ui) { + System.out.print("Wait 30s:"); + for(int i=0;i<30;i++) { + sleep(1000); + System.out.print("."); + if ( !ui.isVisible() ) { + break; + } + } + System.out.println(" OK"); + if ( ui.isVisible() ) { + ui.dispose(); + fail("Forget human check. This unit test need to human decide."); + } + } + + public void testDetailOpenClose() { + setupStaticVar(); + + //åå¾ãããã¤ã¢ãã°ã®é«ãã®ç¢ºèª + if ( openUiHeight == 0 || closeUiHeight == 0 ) { + fail("Dialog Height is wrong"); + } + if ( openUiHeight <= closeUiHeight ) { + fail("Detail Open/Close no diffrent."); + } + } + + public void testErrorAndException() { + //setupStaticVar(); + MessageDialogUI ui = new MessageDialogUI("Check Title `Error` and Exception, Push OK", + new Exception("TEST Exception"), MessageDialogUI.ERROR_MODE); + if ( ui.getHeight() <= closeUiHeight || ui.getHeight() > openUiHeight ) { + fail("Dialog height is wrong."); + } + if ( ui.getTitle().indexOf("Error") < 0 ) { + fail("Dialog title is wrong."); + } + wait(ui); + } + + + public void testInfoNoException() { + //setupStaticVar(); + MessageDialogUI ui = new MessageDialogUI("Check Title 'Information' and no Exception, Push OK", + null, MessageDialogUI.INFORMATION_MODE); + if ( ui.getHeight() >= openUiHeight || ui.getHeight() < closeUiHeight ) { + fail("Dialog height is wrong."); + } + if ( ui.getTitle().indexOf("Information") < 0 ) { + fail("Dialog title is wrong."); + } + wait(ui); + } + + public void testWarningNoException() { + //setupStaticVar(); + MessageDialogUI ui = new MessageDialogUI("Check Title `Warning` and no Exception, Push OK", + null, MessageDialogUI.WARNING_MODE); + if ( ui.getHeight() >= openUiHeight || ui.getHeight() < closeUiHeight ) { + fail("Dialog height is wrong."); + } + if ( ui.getTitle().indexOf("Warning") < 0 ) { + fail("Dialog title is wrong."); + } + wait(ui); + } + +}