Coverage Report - org.doxla.spring.automock.xml.namespace.NamespaceElement
 
Classes in this File Line Coverage Branch Coverage Complexity
NamespaceElement
100% 
100% 
0
 
 1  
 package org.doxla.spring.automock.xml.namespace;
 2  
 
 3  
 import org.doxla.spring.automock.AutoMockExposingPostProcessor;
 4  
 import org.doxla.spring.automock.resolver.InterfaceOnlyPatternMatchingMockResolver;
 5  
 import org.doxla.spring.automock.resolver.MockClassResolver;
 6  
 
 7  
 /**
 8  
  * Defines all of the elements in the automock namespace<br/>
 9  
  * For each element defines the {@link MockClassResolver} class used as the strategy in the {@link AutoMockExposingPostProcessor}<br/>
 10  
  * For each element defines a simple mapping between class property name and element attribute,
 11  
  * eg: new String[]{"resources","mockClassPattern"} defines a mapping between the property 'resources' and the attribute 'mockClassPattern' 
 12  
  * which is defined in the automock.xsd schema. 
 13  
  *  
 14  
  * @author danoxlade
 15  
  */
 16  6
 enum NamespaceElement {
 17  
         
 18  
         /**
 19  
          * Represents the 'interfacePattern' element in the automock namespace<br/>
 20  
          * Defines the mapping for the 'resource' property on {@link InterfaceOnlyPatternMatchingMockResolver}.
 21  
          */
 22  1
         interfacePattern(InterfaceOnlyPatternMatchingMockResolver.class, new String[]{"resources","mockClassPattern"});
 23  
         
 24  
         private Class<? extends MockClassResolver> strategy;
 25  
         private String[][] propertyToAttributeMapping;
 26  
 
 27  
         /**
 28  
          * @throws IllegalArgumentException if the given any of the propertyToAttributeMappings is not of size two, i.e a direct 1-1 mapping.
 29  
          */
 30  1
         private NamespaceElement(Class<? extends MockClassResolver> strategy, String[]... propertyToAttributeMapping){
 31  1
                 this.strategy = strategy;
 32  2
                 for (String[] strings : propertyToAttributeMapping) {
 33  1
                         if(strings.length != 2) throw new IllegalArgumentException("You must specify a direct mapping from property name to attribute name");
 34  
                 }
 35  1
                 this.propertyToAttributeMapping = propertyToAttributeMapping;
 36  1
         }
 37  
 
 38  
         /**
 39  
          * Get the {@link MockClassResolver} class that the {@link NamespaceElement} refers to.
 40  
          * @return a Class of type {@link MockClassResolver}
 41  
          */
 42  
         public Class<? extends MockClassResolver> getStrategyClass() {
 43  1
                 return this.strategy;
 44  
         }
 45  
 
 46  
         /**
 47  
          * Get the list of property to attribute mappings
 48  
          * @return a {@link String} array of property to attribute mappings, the result will always be an array of {@link String} arrays exactly size 2, 
 49  
          * i.e String[][2]
 50  
          */
 51  
         public String[][] propertyToAttributeMappings() {
 52  1
                 return propertyToAttributeMapping;
 53  
         }
 54  
 
 55  
 }