1 | package fr.sii.ogham.core.convert; | |
2 | ||
3 | import java.net.MalformedURLException; | |
4 | import java.net.URL; | |
5 | ||
6 | import fr.sii.ogham.core.exception.convert.ConversionException; | |
7 | ||
8 | /** | |
9 | * Converts a string to an {@link URL}. It uses {@link URL#URL(String)} | |
10 | * constructor to parse the provided url. | |
11 | * | |
12 | * For example: | |
13 | * | |
14 | * <pre> | |
15 | * <code> | |
16 | * String source = "http://foo.bar:8520"; | |
17 | * // calling the converter | |
18 | * URL result = converter.convert(source, URL.class); | |
19 | * System.out.println(result.getProtocol()); | |
20 | * System.out.println(result.getHost()); | |
21 | * System.out.println(result.getPort()); | |
22 | * // prints: | |
23 | * // 'http' | |
24 | * // 'foo.bar' | |
25 | * // 8520 | |
26 | * </code> | |
27 | * </pre> | |
28 | * | |
29 | * | |
30 | * @author Aurélien Baudet | |
31 | * | |
32 | */ | |
33 | public class StringToURLConverter implements SupportingConverter { | |
34 | ||
35 | @SuppressWarnings("unchecked") | |
36 | @Override | |
37 | public <T> T convert(Object source, Class<T> targetType) { | |
38 | String text = (String) source; | |
39 |
4
1. convert : negated conditional → NO_COVERAGE 2. convert : negated conditional → NO_COVERAGE 3. convert : negated conditional → KILLED 4. convert : negated conditional → KILLED |
if(text == null || text.isEmpty()) { |
40 | return null; | |
41 | } | |
42 | try { | |
43 |
2
1. convert : replaced return value with null for fr/sii/ogham/core/convert/StringToURLConverter::convert → NO_COVERAGE 2. convert : replaced return value with null for fr/sii/ogham/core/convert/StringToURLConverter::convert → KILLED |
return (T) new URL(text); |
44 | } catch (MalformedURLException e) { | |
45 | throw new ConversionException("Invalid URL '" + source + "'", e); | |
46 | } | |
47 | } | |
48 | ||
49 | @Override | |
50 | public boolean supports(Class<?> sourceType, Class<?> targetType) { | |
51 |
18
1. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::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/StringToURLConverter::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/StringToURLConverter::supports → KILLED 9. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → KILLED 10. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → KILLED 11. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → KILLED 12. supports : replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::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) && URL.class.isAssignableFrom(targetType); |
52 | } | |
53 | ||
54 | } | |
Mutations | ||
39 |
1.1 2.2 3.3 4.4 |
|
43 |
1.1 2.2 |
|
51 |
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 |