Coverage Report - org.dozer.converters.ByteConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
ByteConverter
75%
6/8
50%
3/6
6
 
 1  
 /*
 2  
  * Copyright 2005-2010 the original author or authors.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.dozer.converters;
 17  
 
 18  
 import org.apache.commons.beanutils.Converter;
 19  
 import org.dozer.util.MappingUtils;
 20  
 
 21  
 /**
 22  
  * Internal class for converting Supported Data Types --> Byte. Only intended for internal use.
 23  
  * 
 24  
  * @author siarhei.krukau
 25  
  */
 26  1
 public class ByteConverter implements Converter {
 27  
 
 28  1
   private static org.apache.commons.beanutils.converters.ByteConverter commonsConverter = new org.apache.commons.beanutils.converters.ByteConverter();
 29  
 
 30  
   @SuppressWarnings("rawtypes")
 31  
   public Object convert(Class destClass, Object srcObj) {
 32  
     // Boolean to Int not supported in apache common's int converter and this is why this class is req'd
 33  6
     if (Boolean.class.isAssignableFrom(srcObj.getClass())) {
 34  0
       boolean value = (Boolean) srcObj;
 35  0
       return (value ? (byte) 1 : (byte) 0);
 36  6
     } else if (MappingUtils.isEnumType(srcObj.getClass())) {
 37  4
       return ((Integer) ((Enum) srcObj).ordinal()).byteValue();
 38  
     } else {
 39  2
       return commonsConverter.convert(destClass, srcObj);
 40  
     }
 41  
   }
 42  
 
 43  
 }