PropertyValueCondition.java

1
package fr.sii.ogham.core.condition;
2
3
import java.util.Objects;
4
5
import fr.sii.ogham.core.env.PropertyResolver;
6
import fr.sii.ogham.core.util.EqualsBuilder;
7
import fr.sii.ogham.core.util.HashCodeBuilder;
8
9
/**
10
 * Condition that checks if the provided property value is the same as the
11
 * provided value.
12
 * 
13
 * @author Aurélien Baudet
14
 *
15
 * @param <T>
16
 *            The type of the object to test for acceptance. Has no effect on
17
 *            the acceptance
18
 */
19
public class PropertyValueCondition<T> implements Condition<T> {
20
	/**
21
	 * The properties to use for checking if property is defined or not
22
	 */
23
	private PropertyResolver propertyResolver;
24
25
	/**
26
	 * The key to check if defined in the properties
27
	 */
28
	private String key;
29
30
	/**
31
	 * The value of the property
32
	 */
33
	private String value;
34
35
	/**
36
	 * Initialize the condition with the provided key. It will check the
37
	 * existence of this key into the provided properties.
38
	 * 
39
	 * @param key
40
	 *            The key of the property
41
	 * @param value
42
	 *            The value of the property
43
	 * @param propertyResolver
44
	 *            the property resolver used to get properties values
45
	 */
46
	public PropertyValueCondition(String key, String value, PropertyResolver propertyResolver) {
47
		super();
48
		this.key = key;
49
		this.value = value;
50
		this.propertyResolver = propertyResolver;
51
	}
52
53
	@Override
54
	public boolean accept(T obj) {
55 4 1. accept : replaced boolean return with false for fr/sii/ogham/core/condition/PropertyValueCondition::accept → NO_COVERAGE
2. accept : replaced boolean return with true for fr/sii/ogham/core/condition/PropertyValueCondition::accept → NO_COVERAGE
3. accept : replaced boolean return with false for fr/sii/ogham/core/condition/PropertyValueCondition::accept → KILLED
4. accept : replaced boolean return with true for fr/sii/ogham/core/condition/PropertyValueCondition::accept → KILLED
		return Objects.equals(propertyResolver.getProperty(key), value);
56
	}
57
58
	@Override
59
	public boolean equals(Object obj) {
60 2 1. equals : replaced boolean return with false for fr/sii/ogham/core/condition/PropertyValueCondition::equals → NO_COVERAGE
2. equals : replaced boolean return with true for fr/sii/ogham/core/condition/PropertyValueCondition::equals → NO_COVERAGE
		return new EqualsBuilder(this, obj).appendFields("key", "value", "propertyResolver").isEqual();
61
	}
62
63
	@Override
64
	public int hashCode() {
65 1 1. hashCode : replaced int return with 0 for fr/sii/ogham/core/condition/PropertyValueCondition::hashCode → NO_COVERAGE
		return new HashCodeBuilder().append(key, value, propertyResolver).hashCode();
66
	}
67
68
	@Override
69
	public String toString() {
70
		StringBuilder builder = new StringBuilder();
71
		builder.append("(").append(key).append("=").append(value).append(" in properties ?)");
72 1 1. toString : replaced return value with "" for fr/sii/ogham/core/condition/PropertyValueCondition::toString → NO_COVERAGE
		return builder.toString();
73
	}
74
}

Mutations

55

1.1
Location : accept
Killed by : oghamcore.ut.core.condition.PropertyValueConditionSpec
replaced boolean return with false for fr/sii/ogham/core/condition/PropertyValueCondition::accept → KILLED

2.2
Location : accept
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/condition/PropertyValueCondition::accept → NO_COVERAGE

3.3
Location : accept
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/condition/PropertyValueCondition::accept → NO_COVERAGE

4.4
Location : accept
Killed by : oghamcore.ut.core.condition.PropertyValueConditionSpec
replaced boolean return with true for fr/sii/ogham/core/condition/PropertyValueCondition::accept → KILLED

60

1.1
Location : equals
Killed by : none
replaced boolean return with false for fr/sii/ogham/core/condition/PropertyValueCondition::equals → NO_COVERAGE

2.2
Location : equals
Killed by : none
replaced boolean return with true for fr/sii/ogham/core/condition/PropertyValueCondition::equals → NO_COVERAGE

65

1.1
Location : hashCode
Killed by : none
replaced int return with 0 for fr/sii/ogham/core/condition/PropertyValueCondition::hashCode → NO_COVERAGE

72

1.1
Location : toString
Killed by : none
replaced return value with "" for fr/sii/ogham/core/condition/PropertyValueCondition::toString → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM