AndCondition.java

1
package fr.sii.ogham.core.condition;
2
3
import java.util.List;
4
5
import fr.sii.ogham.core.util.StringUtils;
6
7
/**
8
 * Condition that provides a logical AND operation on manipulated conditions.
9
 * 
10
 * @author Aurélien Baudet
11
 *
12
 * @param <T>
13
 *            the type of the object to test
14
 */
15
public class AndCondition<T> extends CompositeCondition<T> {
16
17
	/**
18
	 * Initializes the {@code and} operator with none, one or several
19
	 * sub-conditions.
20
	 * 
21
	 * <pre>
22
	 * Condition&lt;String&gt; condition1 = ...
23
	 * Condition&lt;String&gt; condition2 = ...
24
	 * AndCondition&lt;String&gt; myCondition = new AndCondition&lt;&gt;(condition1, condition2);
25
	 * </pre>
26
	 * 
27
	 * Has the same effect as:
28
	 * 
29
	 * <pre>
30
	 * Condition&lt;String&gt; condition1 = ...
31
	 * Condition&lt;String&gt; condition2 = ...
32
	 * AndCondition&lt;String&gt; myCondition = new AndCondition&lt;&gt;();
33
	 * myCondition.and(condition1);
34
	 * myCondition.and(condition2);
35
	 * </pre>
36
	 * 
37
	 * @param conditions
38
	 *            the conditions to register (order is important)
39
	 */
40
	@SafeVarargs
41
	public AndCondition(Condition<T>... conditions) {
42
		super(conditions);
43
	}
44
45
	/**
46
	 * Initializes the {@code and} operator with none, one or several
47
	 * sub-conditions. The list must not be null.
48
	 * 
49
	 * @param conditions
50
	 *            the conditions to register (order is important)
51
	 */
52
	public AndCondition(List<Condition<T>> conditions) {
53
		super(conditions);
54
	}
55
56
	@Override
57
	public boolean accept(T obj) {
58
		for (Condition<T> condition : getConditions()) {
59
			// if the condition rejects the object => stop now
60 7 1. accept : negated conditional → NO_COVERAGE
2. accept : negated conditional → KILLED
3. accept : negated conditional → KILLED
4. accept : negated conditional → KILLED
5. accept : negated conditional → KILLED
6. accept : negated conditional → KILLED
7. accept : negated conditional → KILLED
			if (!condition.accept(obj)) {
61 4 1. accept : replaced boolean return with true for fr/sii/ogham/core/condition/AndCondition::accept → NO_COVERAGE
2. accept : replaced boolean return with true for fr/sii/ogham/core/condition/AndCondition::accept → KILLED
3. accept : replaced boolean return with true for fr/sii/ogham/core/condition/AndCondition::accept → KILLED
4. accept : replaced boolean return with true for fr/sii/ogham/core/condition/AndCondition::accept → KILLED
				return false;
62
			}
63
		}
64
		// none condition has rejected the object => it is accepted
65 7 1. accept : replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → NO_COVERAGE
2. accept : replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED
3. accept : replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED
4. accept : replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED
5. accept : replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED
6. accept : replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED
7. accept : replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED
		return true;
66
	}
67
68
	/**
69
	 * Adds a condition to the current condition. For example:
70
	 * 
71
	 * <pre>
72
	 * AndCondition&lt;String&gt; myCondition = new AndCondition&lt;&gt;();
73
	 * myCondition.and(new FixedCondition&lt;&gt;(true));
74
	 * myCondition.apply("foo"); // will always return true
75
	 * 
76
	 * myCondition.and(new FixedCondition&lt;&gt;(false));
77
	 * myCondition.apply("foo"); // will always return false
78
	 * </pre>
79
	 * 
80
	 * The returned instance is the same as {@code myCondition} so you can also
81
	 * write this:
82
	 * 
83
	 * <pre>
84
	 * AndCondition&lt;String&gt; myCondition = new AndCondition&lt;&gt;();
85
	 * myCondition = myCondition.and(new FixedCondition&lt;&gt;(true));
86
	 * myCondition.apply("foo"); // will always return true
87
	 * 
88
	 * myCondition = myCondition.and(new FixedCondition&lt;&gt;(false));
89
	 * myCondition.apply("foo"); // will always return false
90
	 * </pre>
91
	 * 
92
	 * 
93
	 * @param condition
94
	 *            the condition to add
95
	 * @return this instance for fluent chaining
96
	 */
97
	public AndCondition<T> and(Condition<T> condition) {
98
		addCondition(condition);
99 3 1. and : replaced return value with null for fr/sii/ogham/core/condition/AndCondition::and → SURVIVED
2. and : replaced return value with null for fr/sii/ogham/core/condition/AndCondition::and → NO_COVERAGE
3. and : replaced return value with null for fr/sii/ogham/core/condition/AndCondition::and → KILLED
		return this;
100
	}
101
102
	/**
103
	 * Adds several conditions at once to the current condition. This can be
104
	 * useful when you register each sub-condition into a list:
105
	 * 
106
	 * <pre>
107
	 * List&lt;Condition&lt;String&gt;&gt; conditions = new ArrayList&lt;&gt;();
108
	 * conditions.add(...);
109
	 * conditions.add(...);
110
	 * AndCondition&lt;String&gt; myCondition = new AndCondition&lt;&gt;();
111
	 * myCondition.and(conditions);
112
	 * </pre>
113
	 * 
114
	 * @param conditions
115
	 *            the list of conditions to register
116
	 * @return this instance for fluent chaining
117
	 */
118
	public AndCondition<T> and(List<Condition<T>> conditions) {
119
		addConditions(conditions);
120 1 1. and : replaced return value with null for fr/sii/ogham/core/condition/AndCondition::and → NO_COVERAGE
		return this;
121
	}
122
123
	@Override
124
	public String toString() {
125 1 1. toString : replaced return value with "" for fr/sii/ogham/core/condition/AndCondition::toString → NO_COVERAGE
		return "{" + StringUtils.join(conditions, "} and {") + "}";
126
	}
127
}

Mutations

60

1.1
Location : accept
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : accept
Killed by : oghamspringbootv1autoconfigure.it.SpringWebBeanResolutionTest.smsUsingThymeleafTemplateShouldResolveBeansAndUrls(oghamspringbootv1autoconfigure.it.SpringWebBeanResolutionTest)
negated conditional → KILLED

3.3
Location : accept
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.noHostDefinedShouldFail(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
negated conditional → KILLED

4.4
Location : accept
Killed by : oghamcore.ut.core.condition.fluent.FluentConditionsTest.requiredMailHostAndMailPortProperties(oghamcore.ut.core.condition.fluent.FluentConditionsTest)
negated conditional → KILLED

5.5
Location : accept
Killed by : oghamspringbootv2autoconfigure.it.SpringWebBeanResolutionTest.smsUsingThymeleafTemplateShouldResolveBeansAndUrls(oghamspringbootv2autoconfigure.it.SpringWebBeanResolutionTest)
negated conditional → KILLED

6.6
Location : accept
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
negated conditional → KILLED

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

61

1.1
Location : accept
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.noHostDefinedShouldFail(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
replaced boolean return with true for fr/sii/ogham/core/condition/AndCondition::accept → KILLED

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

3.3
Location : accept
Killed by : oghamcore.ut.core.condition.fluent.FluentConditionsTest.requiredMailHostAndMailPortProperties(oghamcore.ut.core.condition.fluent.FluentConditionsTest)
replaced boolean return with true for fr/sii/ogham/core/condition/AndCondition::accept → KILLED

4.4
Location : accept
Killed by : oghamall.it.email.EmailCustomImplTest.simple(oghamall.it.email.EmailCustomImplTest)
replaced boolean return with true for fr/sii/ogham/core/condition/AndCondition::accept → KILLED

65

1.1
Location : accept
Killed by : oghamcloudhopper.it.AutoRetryExtensionTest.smsNotRetriedDueToCloudhopperError(oghamcloudhopper.it.AutoRetryExtensionTest)
replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED

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

3.3
Location : accept
Killed by : oghamjavamail.it.builder.JavaMailCustomConfigurationTest.oghamPropertyShouldOverride(oghamjavamail.it.builder.JavaMailCustomConfigurationTest)
replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED

4.4
Location : accept
Killed by : oghamspringbootv1autoconfigure.it.SpringWebBeanResolutionTest.smsUsingThymeleafTemplateShouldResolveBeansAndUrls(oghamspringbootv1autoconfigure.it.SpringWebBeanResolutionTest)
replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED

5.5
Location : accept
Killed by : oghamspringbootv2autoconfigure.it.SpringWebBeanResolutionTest.smsUsingThymeleafTemplateShouldResolveBeansAndUrls(oghamspringbootv2autoconfigure.it.SpringWebBeanResolutionTest)
replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED

6.6
Location : accept
Killed by : oghamcore.ut.core.condition.fluent.FluentConditionsTest.requiredMailHostAndMailPortProperties(oghamcore.ut.core.condition.fluent.FluentConditionsTest)
replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED

7.7
Location : accept
Killed by : oghamall.it.configuration.EmptyBuilderTest.emailSenderManuallyRegisteredButUnconfiguredTemplateParsersCantHandleMultiTemplateContent(oghamall.it.configuration.EmptyBuilderTest)
replaced boolean return with false for fr/sii/ogham/core/condition/AndCondition::accept → KILLED

99

1.1
Location : and
Killed by : oghamcore.ut.core.condition.provider.RequiredClassesAnnotationProviderTest.singleRequiredClass(oghamcore.ut.core.condition.provider.RequiredClassesAnnotationProviderTest)
replaced return value with null for fr/sii/ogham/core/condition/AndCondition::and → KILLED

2.2
Location : and
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/AndCondition::and → SURVIVED

3.3
Location : and
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/AndCondition::and → NO_COVERAGE

120

1.1
Location : and
Killed by : none
replaced return value with null for fr/sii/ogham/core/condition/AndCondition::and → NO_COVERAGE

125

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

Active mutators

Tests examined


Report generated by PIT OGHAM