Ignore:
Timestamp:
08/17/12 09:26:21 (12 years ago)
Author:
pharms
Message:
  • adapted to new coding style in quest
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/quest-core-usability-test/src/test/java/de/ugoe/cs/quest/usability/AbstractUsabilityEvaluationTC.java

    r474 r561  
    1 //------------------------------------------------------------------------------------------------- 
    21// Module    : $RCSfile: AbstractUsabilityEvaluationTC.java,v $ 
    32// Version   : $Revision: 0.0 $  $Author: pharms $  $Date: 18.07.2012 $ 
     
    54// Creation  : 2012 by pharms 
    65// Copyright : Patrick Harms, 2012 
    7 //------------------------------------------------------------------------------------------------- 
     6 
     7 
    88package de.ugoe.cs.quest.usability; 
    99 
     
    2121import de.ugoe.cs.quest.tasktrees.testutils.DummyTextField; 
    2222import de.ugoe.cs.quest.tasktrees.testutils.SimpleLogFormatter; 
    23 import de.ugoe.cs.quest.tasktrees.treeifc.Iteration; 
    24 import de.ugoe.cs.quest.tasktrees.treeifc.Selection; 
    25 import de.ugoe.cs.quest.tasktrees.treeifc.Sequence; 
    26 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTree; 
    27 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeBuilder; 
    28 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNode; 
    29 import de.ugoe.cs.quest.tasktrees.treeifc.TaskTreeNodeFactory; 
    30 import de.ugoe.cs.quest.tasktrees.treeifc.TextInputInteractionTask; 
    31 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilderImpl; 
    32 import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactoryImpl; 
    33  
    34 //------------------------------------------------------------------------------------------------- 
     23import de.ugoe.cs.quest.tasktrees.treeifc.IIteration; 
     24import de.ugoe.cs.quest.tasktrees.treeifc.ISelection; 
     25import de.ugoe.cs.quest.tasktrees.treeifc.ISequence; 
     26import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTree; 
     27import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeBuilder; 
     28import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNode; 
     29import de.ugoe.cs.quest.tasktrees.treeifc.ITaskTreeNodeFactory; 
     30import de.ugoe.cs.quest.tasktrees.treeifc.ITextInputEventTask; 
     31import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeBuilder; 
     32import de.ugoe.cs.quest.tasktrees.treeimpl.TaskTreeNodeFactory; 
     33 
    3534/** 
    3635 * TODO comment 
     
    3938 * @author 2012, last modified by $Author: pharms$ 
    4039 */ 
    41 //------------------------------------------------------------------------------------------------- 
    42 public class AbstractUsabilityEvaluationTC 
    43 { 
    44    
    45   /** */ 
    46   private TaskTreeBuilder mTaskTreeBuilder = new TaskTreeBuilderImpl(); 
    47  
    48   /** */ 
    49   private TaskTreeNodeFactory mTaskTreeNodeFactory = new TaskTreeNodeFactoryImpl(); 
    50    
    51   //----------------------------------------------------------------------------------------------- 
    52   /** 
     40public class AbstractUsabilityEvaluationTC { 
     41 
     42    /** */ 
     43    private ITaskTreeBuilder taskTreeBuilder = new TaskTreeBuilder(); 
     44 
     45    /** */ 
     46    private ITaskTreeNodeFactory taskTreeNodeFactory = new TaskTreeNodeFactory(); 
     47 
     48    /** 
    5349   * 
    5450   */ 
    55   //----------------------------------------------------------------------------------------------- 
    56   @Before 
    57   public void setUp() 
    58   { 
    59     Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 
    60   } 
    61  
    62   //----------------------------------------------------------------------------------------------- 
    63   /** 
     51    @Before 
     52    public void setUp() { 
     53        Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter()); 
     54    } 
     55 
     56    /** 
    6457   * 
    6558   */ 
    66   //----------------------------------------------------------------------------------------------- 
    67   protected TaskTree createTaskTree(String spec) 
    68   { 
    69     Matcher matcher = 
    70       Pattern.compile("(\\s*(\\w+)\\s*(\\(((\\w*\\s*)*)\\))?\\s*(\\{))|(\\})").matcher(spec); 
    71        
    72     if (!matcher.find()) 
     59    protected ITaskTree createTaskTree(String spec) { 
     60        Matcher matcher = 
     61            Pattern.compile("(\\s*(\\w+)\\s*(\\(((\\w*\\s*)*)\\))?\\s*(\\{))|(\\})").matcher(spec); 
     62 
     63        if (!matcher.find()) { 
     64            if (!matcher.hitEnd()) { 
     65                throw new IllegalArgumentException("could not parse task specification"); 
     66            } 
     67        } 
     68 
     69        return taskTreeNodeFactory.createTaskTree(parseTask(matcher, new int[1])); 
     70    } 
     71 
     72    /** 
     73     * TODO: comment 
     74     *  
     75     * @param expectedDefects 
     76     * @param evaluateUsability 
     77     */ 
     78    protected void assertUsabilityEvaluationResult(UsabilityDefect[]         expectedDefects, 
     79                                                   UsabilityEvaluationResult evaluationResult) 
    7380    { 
    74       if (!matcher.hitEnd()) 
    75       { 
    76         throw new IllegalArgumentException("could not parse task specification"); 
    77       } 
    78     } 
    79  
    80     return mTaskTreeNodeFactory.createTaskTree(parseTask(matcher, new int[1])); 
    81   } 
    82  
    83   //----------------------------------------------------------------------------------------------- 
    84   /** 
    85    * TODO: comment 
    86    * 
    87    * @param expectedDefects 
    88    * @param evaluateUsability 
    89    */ 
    90   //----------------------------------------------------------------------------------------------- 
    91   protected void assertUsabilityEvaluationResult(UsabilityDefect[]         expectedDefects, 
    92                                                  UsabilityEvaluationResult evaluationResult) 
    93   { 
    94     assertEquals(expectedDefects.length, evaluationResult.getAllDefects().size()); 
    95      
    96     EXPECTED_DEFECT_ITERATION: 
    97     for (UsabilityDefect expectedDefect : expectedDefects) 
    98     { 
    99       for (UsabilityDefect defect : evaluationResult.getAllDefects()) 
    100       { 
    101         if (expectedDefect.equals(defect)) 
    102         { 
    103           System.err.println(defect.getParameterizedDescription()); 
    104           continue EXPECTED_DEFECT_ITERATION; 
    105         } 
    106       } 
    107        
    108       for (UsabilityDefect defect : evaluationResult.getAllDefects()) 
    109       { 
    110         System.err.println(defect); 
    111       } 
    112        
    113       fail("expected defect " + expectedDefect + " not found in evaluation result"); 
    114     } 
    115   } 
    116  
    117  
    118   //----------------------------------------------------------------------------------------------- 
    119   /** 
     81        assertEquals(expectedDefects.length, evaluationResult.getAllDefects().size()); 
     82 
     83        EXPECTED_DEFECT_ITERATION: 
     84        for (UsabilityDefect expectedDefect : expectedDefects) { 
     85            for (UsabilityDefect defect : evaluationResult.getAllDefects()) { 
     86                if (expectedDefect.equals(defect)) { 
     87                    System.err.println(defect.getParameterizedDescription()); 
     88                    continue EXPECTED_DEFECT_ITERATION; 
     89                } 
     90            } 
     91 
     92            for (UsabilityDefect defect : evaluationResult.getAllDefects()) { 
     93                System.err.println(defect); 
     94            } 
     95 
     96            fail("expected defect " + expectedDefect + " not found in evaluation result"); 
     97        } 
     98    } 
     99 
     100    /** 
    120101   *  
    121102   */ 
    122   //----------------------------------------------------------------------------------------------- 
    123   private TaskTreeNode parseTask(Matcher tokenMatcher, int[] typeNumbers) 
    124   { 
    125     String firstToken = tokenMatcher.group(); 
    126      
    127     if ("}".equals(firstToken)) 
    128     { 
    129       throw new IllegalArgumentException("found a closing bracket at an unexpected place"); 
    130     } 
    131      
    132     TaskTreeNode treeNode = instantiateTreeNode(tokenMatcher, typeNumbers); 
    133      
    134     if (!tokenMatcher.find()) 
    135     { 
    136       throw new IllegalArgumentException("could not parse task specification"); 
    137     } 
    138      
    139     firstToken = tokenMatcher.group(); 
    140      
    141     if (!"}".equals(firstToken)) 
    142     { 
    143       TaskTreeNode child = null; 
    144      
    145       do 
    146       { 
    147         child = parseTask(tokenMatcher, typeNumbers); 
    148          
    149         if (child != null) 
    150         { 
    151           addChild(treeNode, child); 
    152            
    153           if (!tokenMatcher.find()) 
    154           { 
     103    private ITaskTreeNode parseTask(Matcher tokenMatcher, int[] typeNumbers) { 
     104        String firstToken = tokenMatcher.group(); 
     105 
     106        if ("}".equals(firstToken)) { 
     107            throw new IllegalArgumentException("found a closing bracket at an unexpected place"); 
     108        } 
     109 
     110        ITaskTreeNode treeNode = instantiateTreeNode(tokenMatcher, typeNumbers); 
     111 
     112        if (!tokenMatcher.find()) { 
    155113            throw new IllegalArgumentException("could not parse task specification"); 
    156           } 
    157            
    158           firstToken = tokenMatcher.group(); 
    159            
    160           if ("}".equals(firstToken)) 
    161           { 
    162             break; 
    163           } 
    164         } 
    165          
    166       } 
    167       while (child != null); 
    168        
    169     } 
    170      
    171     return treeNode; 
    172   } 
    173  
    174   //----------------------------------------------------------------------------------------------- 
    175   /** 
    176    * TODO: comment 
    177    * 
    178    * @param group 
    179    * @return 
    180    */ 
    181   //----------------------------------------------------------------------------------------------- 
    182   private TaskTreeNode instantiateTreeNode(Matcher tokenMatcher, int[] typeNumbers) 
    183   { 
    184     String type = tokenMatcher.group(2); 
    185     String additionalInfo = tokenMatcher.group(4); 
    186      
    187     if ("Interaction".equals(type)) 
    188     { 
    189       return mTaskTreeNodeFactory.createNewInteractionTask 
    190         (new DummyGUIElement("dummy"), new DummyInteraction("dummy", typeNumbers[0]++)); 
    191     } 
    192     else if ("Sequence".equals(type)) 
    193     { 
    194       return mTaskTreeNodeFactory.createNewSequence(); 
    195     } 
    196     else if ("Iteration".equals(type)) 
    197     { 
    198       return mTaskTreeNodeFactory.createNewIteration(); 
    199     } 
    200     else if ("Selection".equals(type)) 
    201     { 
    202       return mTaskTreeNodeFactory.createNewSelection(); 
    203     } 
    204     else if ("TextInput".equals(type)) 
    205     { 
    206       if (additionalInfo == null) 
    207       { 
    208         fail("no simulated text provided for text input interactin task"); 
    209       } 
    210        
    211       TextInputInteractionTask task = 
    212         mTaskTreeNodeFactory.createNewTextInputInteractionTask(new DummyTextField(additionalInfo)); 
    213       
    214       task.setEnteredText(additionalInfo); 
    215       return task; 
    216     } 
    217     else 
    218     { 
    219       fail("invalid type of task tree node: " + type); 
    220       return null; 
    221     } 
    222   } 
    223  
    224   //----------------------------------------------------------------------------------------------- 
    225   /** 
    226    * TODO: comment 
    227    * 
    228    * @param treeNode 
    229    * @param child 
    230    */ 
    231   //----------------------------------------------------------------------------------------------- 
    232   private void addChild(TaskTreeNode parent, TaskTreeNode child) 
    233   { 
    234     if (parent instanceof Sequence) 
    235     { 
    236       mTaskTreeBuilder.addChild((Sequence) parent, child); 
    237     } 
    238     else if (parent instanceof Iteration) 
    239     { 
    240       if (parent.getChildren().size() <= 0) 
    241       { 
    242         mTaskTreeBuilder.setChild((Iteration) parent, child); 
    243       } 
    244       else 
    245       { 
    246         fail("can not add more than one child to an iteration"); 
    247       } 
    248     } 
    249     else if (parent instanceof Selection) 
    250     { 
    251       mTaskTreeBuilder.addChild((Selection) parent, child); 
    252     } 
    253     else if (parent instanceof TextInputInteractionTask) 
    254     { 
    255       mTaskTreeBuilder.addChild((TextInputInteractionTask) parent, child); 
    256     } 
    257     else 
    258     { 
    259       fail("can not add children to parent task tree node of type " + parent.getClass().getName()); 
    260     } 
    261   } 
     114        } 
     115 
     116        firstToken = tokenMatcher.group(); 
     117 
     118        if (!"}".equals(firstToken)) { 
     119            ITaskTreeNode child = null; 
     120 
     121            do { 
     122                child = parseTask(tokenMatcher, typeNumbers); 
     123 
     124                if (child != null) { 
     125                    addChild(treeNode, child); 
     126 
     127                    if (!tokenMatcher.find()) { 
     128                        throw new IllegalArgumentException("could not parse task specification"); 
     129                    } 
     130 
     131                    firstToken = tokenMatcher.group(); 
     132 
     133                    if ("}".equals(firstToken)) { 
     134                        break; 
     135                    } 
     136                } 
     137 
     138            } 
     139            while (child != null); 
     140 
     141        } 
     142 
     143        return treeNode; 
     144    } 
     145 
     146    /** 
     147     * TODO: comment 
     148     *  
     149     * @param group 
     150     * @return 
     151     */ 
     152    private ITaskTreeNode instantiateTreeNode(Matcher tokenMatcher, int[] typeNumbers) { 
     153        String type = tokenMatcher.group(2); 
     154        String additionalInfo = tokenMatcher.group(4); 
     155 
     156        if ("Interaction".equals(type)) { 
     157            return taskTreeNodeFactory.createNewEventTask 
     158                (new DummyInteraction("dummy", typeNumbers[0]++), new DummyGUIElement("dummy")); 
     159        } 
     160        else if ("Sequence".equals(type)) { 
     161            return taskTreeNodeFactory.createNewSequence(); 
     162        } 
     163        else if ("Iteration".equals(type)) { 
     164            return taskTreeNodeFactory.createNewIteration(); 
     165        } 
     166        else if ("Selection".equals(type)) { 
     167            return taskTreeNodeFactory.createNewSelection(); 
     168        } 
     169        else if ("TextInput".equals(type)) { 
     170            if (additionalInfo == null) { 
     171                fail("no simulated text provided for text input interactin task"); 
     172            } 
     173 
     174            ITextInputEventTask task = 
     175                taskTreeNodeFactory.createNewTextInputEventTask(new DummyTextField(additionalInfo)); 
     176 
     177            task.setEnteredText(additionalInfo); 
     178            return task; 
     179        } 
     180        else { 
     181            fail("invalid type of task tree node: " + type); 
     182            return null; 
     183        } 
     184    } 
     185 
     186    /** 
     187     * TODO: comment 
     188     *  
     189     * @param treeNode 
     190     * @param child 
     191     */ 
     192    private void addChild(ITaskTreeNode parent, ITaskTreeNode child) { 
     193        if (parent instanceof ISequence) { 
     194            taskTreeBuilder.addChild((ISequence) parent, child); 
     195        } 
     196        else if (parent instanceof IIteration) { 
     197            if (parent.getChildren().size() <= 0) { 
     198                taskTreeBuilder.setChild((IIteration) parent, child); 
     199            } 
     200            else { 
     201                fail("can not add more than one child to an iteration"); 
     202            } 
     203        } 
     204        else if (parent instanceof ISelection) { 
     205            taskTreeBuilder.addChild((ISelection) parent, child); 
     206        } 
     207        else if (parent instanceof ITextInputEventTask) { 
     208            taskTreeBuilder.addChild((ITextInputEventTask) parent, child); 
     209        } 
     210        else { 
     211            fail("can not add children to parent task tree node of type " + 
     212                 parent.getClass().getName()); 
     213        } 
     214    } 
    262215 
    263216} 
Note: See TracChangeset for help on using the changeset viewer.