Clover coverage report - JBind Project
Coverage timestamp: Fr Mai 28 2004 11:17:36 CEST
file stats: LOC: 86   Methods: 4
NCLOC: 66   Classes: 1
This license of Clover is provided to support the development of JBind only. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover.
 
 Source file Conditionals Statements Methods TOTAL
XmlTest.java 61,1% 79,4% 100% 75%
 1   
 /*
 2   
  * JBind
 3   
  *
 4   
  * Copyright (c) by Stefan Wachter. All rights reserved.
 5   
  *
 6   
  * Usage, modification, and redistribution is subject to license terms that are
 7   
  * available at 'http://www.jbind.org'. The JBind license is like the
 8   
  * 'Apache Software License V 1.1'.
 9   
  */
 10   
 package org.jbind.xml.test;
 11   
 
 12   
 import java.io.File;
 13   
 import java.net.URL;
 14   
 import java.util.ArrayList;
 15   
 import java.util.Iterator;
 16   
 import java.util.List;
 17   
 
 18   
 import junit.framework.TestCase;
 19   
 
 20   
 import org.jbind.message.IMessage;
 21   
 import org.jbind.xml.msg.IConstraintViolations;
 22   
 
 23   
 public class XmlTest extends TestCase {
 24   
 
 25   
   private String myScenarioName = null;
 26   
   private File myScenarioDir = null;
 27   
   private TestInfo myInfo = null;
 28   
 
 29   
   private static boolean DEBUG = false;
 30   
 
 31  58
   public XmlTest(String aTestName, String aScenarioName, File aScenarioDir, TestInfo anInfo) {
 32  58
     super(aTestName);
 33  58
     myScenarioName = aScenarioName;
 34  58
     myScenarioDir = aScenarioDir;
 35  58
     myInfo = anInfo;
 36   
   }
 37   
 
 38  4
   protected URL getFileUrl(String aRelativeFileName) throws Exception {
 39  4
     return new File(myScenarioDir, aRelativeFileName).toURL();
 40   
   }
 41   
 
 42  55
   protected void checkErrorMessages(IConstraintViolations aViolations) {
 43  55
     List cvsList = new ArrayList();
 44  55
     for (Iterator i = aViolations.iterSimpleMessages(); i.hasNext(); ) {
 45  29
       cvsList.add(i.next());
 46   
     }
 47  55
     StringBuffer missingMessages = new StringBuffer();
 48  55
     for (Iterator i = myInfo.iterErrorMessageInfos(); i.hasNext(); ) {
 49  29
       ErrorMessageInfo errorMessageInfo = (ErrorMessageInfo)i.next();
 50  29
       boolean found = false;
 51  43
       for (Iterator j = cvsList.iterator(); j.hasNext(); ) {
 52  43
         IMessage m = (IMessage)j.next();
 53  43
         String s = m.output(null);
 54  43
         if (errorMessageInfo.isMatched(s)) {
 55  29
           j.remove();
 56  29
           found = true;
 57  29
           break;
 58   
         }
 59   
       }
 60  29
       if (!found) {
 61  0
         missingMessages.append("\n\t").append(errorMessageInfo.pattern);
 62   
       }
 63   
     }
 64  55
     StringBuffer unexpectedMessages = new StringBuffer();
 65  55
     for (Iterator i = cvsList.iterator(); i.hasNext(); ) {
 66  0
       IMessage m = (IMessage)i.next();
 67  0
       unexpectedMessages.append("\n\t").append(m.output(null));
 68  0
       if (DEBUG) {
 69  0
         unexpectedMessages.append("\n").append(m.getOrigin());
 70   
       }
 71   
     }
 72  55
     StringBuffer msg = new StringBuffer();
 73  55
     if (missingMessages.length() > 0) {
 74  0
       msg.append("\nMissing messages:\n").append(missingMessages);
 75   
     }
 76  55
     if (unexpectedMessages.length() > 0) {
 77  0
       msg.append("\nUnexpectedMessages:\n").append(unexpectedMessages);
 78   
     }
 79  55
     assertTrue(msg.toString(), msg.length() == 0);
 80   
   }
 81   
 
 82  5
   protected TestInfo getTestInfo() {
 83  5
     return myInfo;
 84   
   }
 85   
 }
 86