changeset 715:01c529dee2b7

refactoring of AWTHelper (class from AWTFramework)
author Jana Fabrikova <jfabriko@redhat.com>
date Thu, 02 May 2013 15:55:51 +0200
parents 55c943c320fd
children 882d1bc0ff8f
files ChangeLog tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java
diffstat 2 files changed, 42 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu May 02 15:31:55 2013 +0200
+++ b/ChangeLog	Thu May 02 15:55:51 2013 +0200
@@ -1,3 +1,13 @@
+2013-05-02  Jana Fabrikova  <jfabriko@redhat.com>
+
+	* tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java:
+	refactoring - removing initStrGiven variable - now it only
+	matters if the initStr is null or not. Modifying the following
+	two methods: (charReaded) - if initStr is null the run method
+	can not be started from charReaded and the presence of initStr
+	is not checked in stdout. Method (getInitStrAsRule) returns rule
+	that is always true if initStr is null.
+
 2013-05-02  Jiri Vanek  <jvanek@redhat.com>
 
 	Renamed cz locales to be more general
--- a/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java	Thu May 02 15:31:55 2013 +0200
+++ b/tests/test-extensions/net/sourceforge/jnlp/awt/AWTHelper.java	Thu May 02 15:55:51 2013 +0200
@@ -60,7 +60,7 @@
 public abstract class AWTHelper extends RulesFolowingClosingListener implements Runnable{
 
     //attributes possibly set by user
-    private String initStr = "";        
+    private String initStr = null;        
     private Color appletColor;
     private BufferedImage marker;
     private Point markerPosition;
@@ -75,7 +75,6 @@
     private BufferedImage screenshot;
     private Robot robot;
     private boolean appletFound = false;
-    private boolean initStrGiven = false; //impossible to find in the output if not given
     private boolean appletColorGiven = false; //impossible to search for color difference if not given
     private boolean markerGiven = false; //impossible to find the applet if marker not given
     private boolean appletDimensionGiven = false;
@@ -117,7 +116,6 @@
         this();
         
         this.initStr = initStr;
-        this.initStrGiven = true;
     }
     
     /**
@@ -148,7 +146,6 @@
         this(icon, iconPosition, appletWidth, appletHeight);
         
         this.initStr = initString;
-        this.initStrGiven = true;
     }
     
     /**
@@ -176,7 +173,6 @@
     public AWTHelper(String initString, int appletWidth, int appletHeight){
         this(appletWidth, appletHeight);
         this.initStr = initString;
-        this.initStrGiven = true;
     }
     
     /**
@@ -194,6 +190,8 @@
      * override of method charReaded (from RulesFolowingClosingListener)
      * 
      * waiting for the applet, when applet is ready run action thread
+     * (if initStr==null, do not check and do not call run)
+     * 
      * when all the wanted strings are in the stdout, applet can be closed
      * 
      * @param ch 
@@ -202,7 +200,8 @@
     public void charReaded(char ch) {
         sb.append(ch);
         //is applet ready to start clicking?
-        if (initStrGiven && !actionStarted && appletIsReady(sb.toString())) {
+        //check and run applet only if initStr is not null
+        if ((initStr != null) && !actionStarted && appletIsReady(sb.toString())) {
             try{
                 actionStarted = true; 
                 this.findAndActivateApplet();
@@ -241,22 +240,43 @@
      * @return
      */
     public Rule getInitStrAsRule(){
-        return new ContainsRule(this.initStr);
+    	if( initStr != null ){
+            return new ContainsRule(this.initStr);
+    	}else{
+    		return new Rule(){
+
+				@Override
+				public void setRule(Object rule) {
+				}
+
+				@Override
+				public boolean evaluate(Object upon) {
+					return true;
+				}
+
+				@Override
+				public String toPassingString() {
+					return "nothing to check, initStr is null";
+				}
+
+				@Override
+				public String toFailingString() {
+					return "nothing to check, initStr is null";
+				}
+    			
+    		} ;
+    	}
     }
     
     //boolean controls getters
     protected boolean appletIsReady(String content) {
-        return (content.contains(initStr));
+        return this.getInitStrAsRule().evaluate(content);
     }
     
     public boolean isActionStarted() {
         return actionStarted;
     }
     
-    public boolean isInitStrGiven(){
-        return initStrGiven;
-    }
-    
     public boolean isAppletColorGiven(){
         return appletColorGiven;
     }
@@ -292,7 +312,6 @@
 
     public void setInitStr(String initStr) {
         this.initStr = initStr;
-        this.initStrGiven = true;
     }
        
     public void setMarker(BufferedImage marker, Point markerPosition) {