| 1 | package fr.sii.ogham.core.convert; | |
| 2 | ||
| 3 | import java.nio.charset.Charset; | |
| 4 | import java.nio.charset.UnsupportedCharsetException; | |
| 5 | ||
| 6 | import fr.sii.ogham.core.exception.convert.ConversionException; | |
| 7 | ||
| 8 | /** | |
| 9 |  * Converts a string to a {@link Charset} instance. It uses | |
| 10 |  * {@link Charset#forName(String)} to instantiate the charset. | |
| 11 |  *  | |
| 12 |  *  | |
| 13 |  * @author Aurélien Baudet | |
| 14 |  * | |
| 15 |  */ | |
| 16 | public class StringToCharsetConverter implements SupportingConverter { | |
| 17 | ||
| 18 | 	@SuppressWarnings("unchecked") | |
| 19 | 	@Override | |
| 20 | 	public <T> T convert(Object source, Class<T> targetType) { | |
| 21 | 		String charsetName = (String) source; | |
| 22 | 4
1. convert : negated conditional → NO_COVERAGE 2. convert : negated conditional → NO_COVERAGE 3. convert : negated conditional → KILLED 4. convert : negated conditional → KILLED | 		if (charsetName == null || charsetName.isEmpty()) { | 
| 23 | 			return null; | |
| 24 | 		} | |
| 25 | 		try { | |
| 26 | 2
1. convert : replaced return value with null for fr/sii/ogham/core/convert/StringToCharsetConverter::convert → NO_COVERAGE 2. convert : replaced return value with null for fr/sii/ogham/core/convert/StringToCharsetConverter::convert → KILLED | 			return (T) Charset.forName(charsetName); | 
| 27 | 		} catch(UnsupportedCharsetException e) { | |
| 28 | 			throw new ConversionException("Failed to convert "+charsetName+" into Charset", e); | |
| 29 | 		} | |
| 30 | 	} | |
| 31 | ||
| 32 | 	@Override | |
| 33 | 	public boolean supports(Class<?> sourceType, Class<?> targetType) { | |
| 34 | 18
1. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToCharsetConverter::supports → NO_COVERAGE 2. supports : negated conditional → NO_COVERAGE 3. supports : negated conditional → SURVIVED 4. supports : negated conditional → NO_COVERAGE 5. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToCharsetConverter::supports → TIMED_OUT 6. supports : negated conditional → TIMED_OUT 7. supports : negated conditional → TIMED_OUT 8. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToCharsetConverter::supports → KILLED 9. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToCharsetConverter::supports → KILLED 10. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToCharsetConverter::supports → KILLED 11. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToCharsetConverter::supports → KILLED 12. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToCharsetConverter::supports → KILLED 13. supports : negated conditional → KILLED 14. supports : negated conditional → KILLED 15. supports : negated conditional → KILLED 16. supports : negated conditional → KILLED 17. supports : negated conditional → KILLED 18. supports : negated conditional → KILLED | 		return String.class.isAssignableFrom(sourceType) && Charset.class.isAssignableFrom(targetType); | 
| 35 | 	} | |
| 36 | ||
| 37 | } | |
| Mutations | ||
| 22 | 1.1 2.2 3.3 4.4 | |
| 26 | 1.1 2.2 | |
| 34 | 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 13.13 14.14 15.15 16.16 17.17 18.18 |