1 16 package net.sf.dozer.util.mapping; 17 18 import java.util.Iterator ; 19 20 import net.sf.dozer.util.mapping.fieldmap.ClassMap; 21 import net.sf.dozer.util.mapping.fieldmap.FieldMap; 22 import net.sf.dozer.util.mapping.fieldmap.Mappings; 23 import net.sf.dozer.util.mapping.util.MappingFileReader; 24 import net.sf.dozer.util.mapping.util.MappingUtils; 25 import net.sf.dozer.util.mapping.util.MappingsParser; 26 27 30 public class MappingUtilsTest extends DozerTestBase { 31 32 MappingUtils mappingUtils = new MappingUtils(); 33 34 public void testIsBlankOrNull() throws Exception { 35 assertTrue(mappingUtils.isBlankOrNull(null)); 36 assertTrue(mappingUtils.isBlankOrNull("")); 37 assertTrue(mappingUtils.isBlankOrNull(" ")); 38 } 39 40 public void testOverridenFields() throws Exception { 41 MappingFileReader fileReader = new MappingFileReader("overridemapping.xml"); 42 Mappings mappings = fileReader.read(); 43 MappingsParser mappingsParser = new MappingsParser(); 44 mappingsParser.parseMappings(mappings); 45 Iterator iter = mappings.getMapping().iterator(); 47 while (iter.hasNext()) { 48 ClassMap classMap = (ClassMap) iter.next(); 49 if (classMap.getSourceClass().getName().equals("net.sf.dozer.util.mapping.vo.FurtherTestObject")) { 50 assertTrue(classMap.getStopOnErrors()); 51 } 52 if (classMap.getSourceClass().getName().equals("net.sf.dozer.util.mapping.vo.SuperSuperSuperClass")) { 53 assertTrue(classMap.getWildcard()); 54 } 55 if (classMap.getSourceClass().getName().equals("net.sf.dozer.util.mapping.vo.TestObject")) { 56 assertTrue(!((FieldMap) classMap.getFieldMaps().get(0)).getCopyByReference()); 57 } 58 } 59 } 60 61 public void testGetClassWithoutPackage() throws Exception { 62 String result = mappingUtils.getClassNameWithoutPackage(String .class); 63 assertNotNull("result should not be null", result); 64 assertEquals("invalid result value", "String", result); 65 } 66 67 public void testThrowMappingException_MappingException() { 68 MappingException ex = new MappingException(String.valueOf(System.currentTimeMillis())); 69 try { 70 mappingUtils.throwMappingException(ex); 71 fail("should have thrown exception"); 72 } catch (MappingException e) { 73 assertEquals("invalid ex", ex, e); 74 } 75 } 76 77 public void testThrowMappingException_RuntimeException() { 78 NullPointerException ex = new NullPointerException (String.valueOf(System.currentTimeMillis())); 80 try { 81 mappingUtils.throwMappingException(ex); 82 fail("should have thrown exception"); 83 } catch (NullPointerException e) { 84 assertEquals("invalid ex", ex, e); 85 } catch (Throwable e) { 86 fail("NullPointerException should have been thrown"); 87 } 88 } 89 90 public void testThrowMappingException_CheckedException() { 91 NoSuchFieldException ex = new NoSuchFieldException (String.valueOf(System.currentTimeMillis())); 93 try { 94 mappingUtils.throwMappingException(ex); 95 fail("should have thrown exception"); 96 } catch (MappingException e) { 97 assertEquals("invalid nested ex", ex, e.getCause()); 98 } catch (Throwable e) { 99 fail("MappingException should have been thrown"); 100 } 101 } 102 103 } 104 | Popular Tags |