Coverage Report - net.sf.cotta.test.assertion.TestSuiteAssert
 
Classes in this File Line Coverage Branch Coverage Complexity
TestSuiteAssert
0%
0/29
0%
0/18
4
 
 1  
 package net.sf.cotta.test.assertion;
 2  
 
 3  
 import junit.framework.Test;
 4  
 import junit.framework.TestCase;
 5  
 import junit.framework.TestSuite;
 6  
 import org.junit.Assert;
 7  
 
 8  
 import java.util.Enumeration;
 9  
 
 10  
 public class TestSuiteAssert extends BaseAssert<TestSuite, TestSuiteAssert> {
 11  
   public TestSuiteAssert(TestSuite suite) {
 12  0
     super(suite);
 13  0
   }
 14  
 
 15  
   public TestSuiteAssert hasTest(Class testClass, String testName) {
 16  0
     if (match(testClass, testName, value())) {
 17  0
       return this;
 18  
     }
 19  0
     StringBuilder buffer = new StringBuilder("Test suite should have test of class ");
 20  0
     buffer.append(" <").append(testClass).append("> with name <").append(testName).append("> but got ");
 21  0
     buffer.append(value().testCount()).append(" <");
 22  0
     describeActual(buffer, value());
 23  0
     Assert.fail(buffer.toString());
 24  0
     return this;
 25  
   }
 26  
 
 27  
   private boolean match(Class testClass, String testName, TestSuite testSuite) {
 28  0
     for (Enumeration<Test> enumeration = testSuite.tests(); enumeration.hasMoreElements();) {
 29  0
       Test test = enumeration.nextElement();
 30  0
       if (test instanceof TestCase) {
 31  0
         if (test.getClass().equals(testClass) && ((TestCase) test).getName().equals(testName)) {
 32  0
           return true;
 33  
         }
 34  0
       } else if (match(testClass, testName, (TestSuite) test)) {
 35  0
         return true;
 36  
       }
 37  0
     }
 38  0
     return false;
 39  
   }
 40  
 
 41  
   private void describeActual(StringBuilder buffer, TestSuite value) {
 42  0
     for (Enumeration<Test> enumeration = value.tests(); enumeration.hasMoreElements();) {
 43  0
       Test test = enumeration.nextElement();
 44  0
       if (test instanceof TestCase) {
 45  0
         TestCase testCase = (TestCase) test;
 46  0
         buffer.append(testCase.getClass()).append("(").append(testCase.getName()).append(")\n");
 47  0
       } else if (test instanceof TestSuite) {
 48  0
         TestSuite testSuite = (TestSuite) test;
 49  0
         describeActual(buffer, testSuite);
 50  
       }
 51  0
     }
 52  0
   }
 53  
 }