StringToURLConverter.java

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
Location : convert
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : convert
Killed by : oghamcore.ut.core.convert.StringToURLConverterSpec
negated conditional → KILLED

3.3
Location : convert
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : convert
Killed by : oghamcore.ut.core.convert.StringToURLConverterSpec
negated conditional → KILLED

43

1.1
Location : convert
Killed by : oghamcore.ut.core.convert.StringToURLConverterSpec
replaced return value with null for fr/sii/ogham/core/convert/StringToURLConverter::convert → KILLED

2.2
Location : convert
Killed by : none
replaced return value with null for fr/sii/ogham/core/convert/StringToURLConverter::convert → NO_COVERAGE

51

1.1
Location : supports
Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec
replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → KILLED

2.2
Location : supports
Killed by : oghamcore.ut.core.convert.StringToURLConverterSpec
replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → KILLED

3.3
Location : supports
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → KILLED

4.4
Location : supports
Killed by : oghamjavamail.it.builder.OverridePropertiesTest.overrideProperties(oghamjavamail.it.builder.OverridePropertiesTest)
replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → KILLED

5.5
Location : supports
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → NO_COVERAGE

6.6
Location : supports
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → TIMED_OUT

7.7
Location : supports
Killed by : oghamcloudhopper.it.ConnectionFailureTest.invalidSystemId(oghamcloudhopper.it.ConnectionFailureTest)
replaced boolean return with true for fr/sii/ogham/core/convert/StringToURLConverter::supports → KILLED

8.8
Location : supports
Killed by : none
negated conditional → TIMED_OUT

9.9
Location : supports
Killed by : oghamcore.ut.core.convert.StringToURLConverterSpec
negated conditional → KILLED

10.10
Location : supports
Killed by : none
negated conditional → NO_COVERAGE

11.11
Location : supports
Killed by : none
negated conditional → SURVIVED

12.12
Location : supports
Killed by : none
negated conditional → TIMED_OUT

13.13
Location : supports
Killed by : oghamcloudhopper.it.ConnectionFailureTest.invalidSystemId(oghamcloudhopper.it.ConnectionFailureTest)
negated conditional → KILLED

14.14
Location : supports
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
negated conditional → KILLED

15.15
Location : supports
Killed by : oghamjavamail.it.builder.OverridePropertiesTest.overrideProperties(oghamjavamail.it.builder.OverridePropertiesTest)
negated conditional → KILLED

16.16
Location : supports
Killed by : oghamsmsglobal.it.SmsglobalServiceProviderConfigurerSpec
negated conditional → KILLED

17.17
Location : supports
Killed by : oghamcore.ut.core.convert.StringToURLConverterSpec
negated conditional → KILLED

18.18
Location : supports
Killed by : none
negated conditional → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM