Analyzers give an easy way to analyze the results of test steps. Users can write their own analyzers by extending AnalyzerParameterImpl (or by implementing AnalyzerParameter).

Following is an example of an text analyzer:
 
package jsystem.extensions.analyzers.text;

public class FindText extends AnalyzeTextParameter {

    protected boolean isRegExp = false;

    public FindText(String toFind) {
        this.toFind = toFind;
    }

    public FindText(String toFind, boolean isRegExp) {
        this(toFind);
        this.isRegExp = isRegExp;
    }

    public void analyze() {
      
        message = testText;
   
        if (testText == null) {
            title = "Text to analyze is null";
            status = false;
        }
      
        if (isRegExp) {
            status = testText.matches(".*" + toFind + ".*");
        } else {
            status = (testText.indexOf(toFind) > 0);
        }
      
        if (status) {
            title = "The text: >" + toFind + "< was found";
        } else {
            title = "The text: >" + toFind + "< wasn't found";
        }
    
    }

}

FindText is an analyzer that verifies that a certain string is found. It supports regular expressions. The analyze method does most of the work. testText is a string that will be set by the system object using this analyzer by calling setTestAgainsObject method.

The analyze method should set the value of three fields: title, message and status. If the status is set to false the test will fail (throwing an exception). All the results will be reported to the reporter.

Following is an example of a test using analyzer:
 
package tests.jsystem.framework.analyzer;

import junit.framework.SystemTestCase;
import systemobject.tests.Device1;
import jsystem.extensions.analyzers.text.FindText;
import jsystem.framework.analyzer.AnalyzerException;

public class AnalyzerTest extends SystemTestCase {

    Device1 device;
   
   public void setUp() throws Exception {
        device = (Device1)system.getSystemObject("device1");
    }
   
    public void testSetAndAnalyze() throws AnalyzerException {
        device.telnet.dirCommand();
        device.telnet.analyze(new FindText("Program Files"));
    }

}

In the example above the test uses the analyzer to test that the string "Program Files" is found in the output of a dir command. The result of the dir command (in this case a string) is set to the analyzer using the setTestAgainsObject method.