JavaPropertiesResolver.java

1
package fr.sii.ogham.core.env;
2
3
import java.util.Properties;
4
5
import fr.sii.ogham.core.convert.Converter;
6
7
/**
8
 * Simple property resolver that delegates property resolution to a
9
 * {@link Properties} instance. Conversion of raw property values are done by
10
 * the provided {@link Converter} instance.
11
 * 
12
 * @author Aurélien Baudet
13
 *
14
 */
15
public class JavaPropertiesResolver implements PropertyResolver {
16
	private final Properties properties;
17
	private final Converter converter;
18
19
	/**
20
	 * Initializes with the {@link Properties} instance that is used to check
21
	 * property existence and get property values. Provperty values are then
22
	 * converted using the provided {@link Converter}.
23
	 * 
24
	 * @param properties
25
	 *            the properties map
26
	 * @param converter
27
	 *            used to convert raw values
28
	 */
29
	public JavaPropertiesResolver(Properties properties, Converter converter) {
30
		super();
31
		this.properties = properties;
32
		this.converter = converter;
33
	}
34
35
	@Override
36
	public boolean containsProperty(String key) {
37 2 1. containsProperty : replaced boolean return with true for fr/sii/ogham/core/env/JavaPropertiesResolver::containsProperty → RUN_ERROR
2. containsProperty : replaced boolean return with false for fr/sii/ogham/core/env/JavaPropertiesResolver::containsProperty → RUN_ERROR
		return properties.containsKey(key);
38
	}
39
40
	@Override
41
	public String getProperty(String key) {
42 1 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → NO_COVERAGE
		return properties.getProperty(key);
43
	}
44
45
	@Override
46
	public String getProperty(String key, String defaultValue) {
47 1 1. getProperty : replaced return value with "" for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → NO_COVERAGE
		return properties.getProperty(key, defaultValue);
48
	}
49
50
	@Override
51
	public <T> T getProperty(String key, Class<T> targetType) {
52
		Object property = properties.get(key);
53 1 1. getProperty : replaced return value with null for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → RUN_ERROR
		return converter.convert(property, targetType);
54
	}
55
56
	@Override
57
	public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
58
		String property = getProperty(key);
59 1 1. getProperty : negated conditional → NO_COVERAGE
		if (property == null) {
60 1 1. getProperty : replaced return value with null for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → NO_COVERAGE
			return defaultValue;
61
		}
62 1 1. getProperty : replaced return value with null for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → NO_COVERAGE
		return converter.convert(property, targetType);
63
	}
64
65
	@Override
66
	public String getRequiredProperty(String key) {
67
		String property = getProperty(key);
68 1 1. getRequiredProperty : negated conditional → NO_COVERAGE
		if (property == null) {
69
			throw new IllegalStateException("no value for required property " + key);
70
		}
71 1 1. getRequiredProperty : replaced return value with "" for fr/sii/ogham/core/env/JavaPropertiesResolver::getRequiredProperty → NO_COVERAGE
		return property;
72
	}
73
74
	@Override
75
	public <T> T getRequiredProperty(String key, Class<T> targetType) {
76
		String property = getProperty(key);
77 1 1. getRequiredProperty : negated conditional → NO_COVERAGE
		if (property == null) {
78
			throw new IllegalStateException("no value for required property " + key);
79
		}
80 1 1. getRequiredProperty : replaced return value with null for fr/sii/ogham/core/env/JavaPropertiesResolver::getRequiredProperty → NO_COVERAGE
		return converter.convert(property, targetType);
81
	}
82
83
}

Mutations

37

1.1
Location : containsProperty
Killed by :
replaced boolean return with true for fr/sii/ogham/core/env/JavaPropertiesResolver::containsProperty → RUN_ERROR

2.2
Location : containsProperty
Killed by :
replaced boolean return with false for fr/sii/ogham/core/env/JavaPropertiesResolver::containsProperty → RUN_ERROR

42

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → NO_COVERAGE

47

1.1
Location : getProperty
Killed by :
replaced return value with "" for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → NO_COVERAGE

53

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → RUN_ERROR

59

1.1
Location : getProperty
Killed by :
negated conditional → NO_COVERAGE

60

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → NO_COVERAGE

62

1.1
Location : getProperty
Killed by :
replaced return value with null for fr/sii/ogham/core/env/JavaPropertiesResolver::getProperty → NO_COVERAGE

68

1.1
Location : getRequiredProperty
Killed by :
negated conditional → NO_COVERAGE

71

1.1
Location : getRequiredProperty
Killed by :
replaced return value with "" for fr/sii/ogham/core/env/JavaPropertiesResolver::getRequiredProperty → NO_COVERAGE

77

1.1
Location : getRequiredProperty
Killed by :
negated conditional → NO_COVERAGE

80

1.1
Location : getRequiredProperty
Killed by :
replaced return value with null for fr/sii/ogham/core/env/JavaPropertiesResolver::getRequiredProperty → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.13.1