| 1 | package fr.sii.ogham.core.condition.fluent; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | import java.util.regex.Pattern; | |
| 5 | ||
| 6 | import fr.sii.ogham.core.condition.AndCondition; | |
| 7 | import fr.sii.ogham.core.condition.Condition; | |
| 8 | import fr.sii.ogham.core.condition.FixedCondition; | |
| 9 | import fr.sii.ogham.core.condition.NotCondition; | |
| 10 | import fr.sii.ogham.core.condition.OrCondition; | |
| 11 | import fr.sii.ogham.core.condition.PropertyPatternCondition; | |
| 12 | import fr.sii.ogham.core.condition.PropertyValueCondition; | |
| 13 | import fr.sii.ogham.core.condition.RequiredClassCondition; | |
| 14 | import fr.sii.ogham.core.condition.RequiredPropertyCondition; | |
| 15 | import fr.sii.ogham.core.env.PropertyResolver; | |
| 16 | ||
| 17 | /** | |
| 18 | * Helper to write fluent conditions like: | |
| 19 | * | |
| 20 | * <pre> | |
| 21 | * requiredClass("javax.mail.Transport").and(not(requiredClass("foo.Bar"))); | |
| 22 | * </pre> | |
| 23 | * | |
| 24 | * To do this, you need to add the following static import: | |
| 25 | * | |
| 26 | * <pre> | |
| 27 | * import static fr.sii.ogham.core.condition.fluent.Conditions.*; | |
| 28 | * </pre> | |
| 29 | * | |
| 30 | * <p> | |
| 31 | * If you are using Java 7, you may need to use {@link MessageConditions} | |
| 32 | * instead because Java 7 doesn't resolve correctly generics chaining. | |
| 33 | * | |
| 34 | * @author Aurélien Baudet | |
| 35 | * | |
| 36 | */ | |
| 37 | public final class Conditions { | |
| 38 | /** | |
| 39 | * Parenthesis operator to handle priorities: | |
| 40 | * | |
| 41 | * <pre> | |
| 42 | * $(requiredProperty(propertyResolver, "mail.host").or(requiredProperty(propertyResolver, "mail.smtp.host"))) | |
| 43 | * .and(requiredProperty(propertyResolver, "mail.port").or(requiredProperty(propertyResolver, "mail.smtp.port"))) | |
| 44 | * </pre> | |
| 45 | * | |
| 46 | * Meaning "(mail.host is defined OR mail.smtp.host is defined) AND | |
| 47 | * (mail.port is defined OR mail.smtp.port is defined)". | |
| 48 | * | |
| 49 | * <p> | |
| 50 | * Without this operator, you had to write this: | |
| 51 | * | |
| 52 | * <pre> | |
| 53 | * requiredProperty(propertyResolver, "mail.host").or(requiredProperty(propertyResolver, "mail.smtp.host")) | |
| 54 | * .and(requiredProperty(propertyResolver, "mail.port").or(requiredProperty(propertyResolver, "mail.smtp.port")) | |
| 55 | * </pre> | |
| 56 | * | |
| 57 | * Meaning "mail.host is defined OR mail.smtp.host is defined AND (mail.port | |
| 58 | * is defined OR mail.smtp.port is defined)". | |
| 59 | * | |
| 60 | * So the behavior won't be the same. | |
| 61 | * | |
| 62 | * @param condition | |
| 63 | * the condition to surround | |
| 64 | * @param <T> | |
| 65 | * the type of the object that is under condition | |
| 66 | * @return the fluent condition | |
| 67 | */ | |
| 68 | @SuppressWarnings("squid:S00100") | |
| 69 | public static <T> FluentCondition<T> $(Condition<T> condition) { | |
| 70 |
2
1. $ : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::$ → NO_COVERAGE 2. $ : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::$ → KILLED |
return new FluentCondition<>(condition); |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * And operator between the provided conditions: | |
| 75 | * | |
| 76 | * <pre> | |
| 77 | * and(requiredClass("javax.mail.Transport"), requiredClass("foo.Bar")); | |
| 78 | * </pre> | |
| 79 | * | |
| 80 | * Means that the result will be true only if | |
| 81 | * <code>javax.mail.Transport</code> and <code>foo.Bar</code> classes are | |
| 82 | * present in the classpath. | |
| 83 | * | |
| 84 | * <p> | |
| 85 | * If one of the condition result is false, then other conditions are not | |
| 86 | * evaluated. | |
| 87 | * </p> | |
| 88 | * | |
| 89 | * @param conditions | |
| 90 | * one or several conditions | |
| 91 | * @param <T> | |
| 92 | * the type of the object that is under condition | |
| 93 | * @return the fluent condition | |
| 94 | */ | |
| 95 | @SafeVarargs | |
| 96 | public static <T> FluentCondition<T> and(Condition<T>... conditions) { | |
| 97 |
2
1. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::and → NO_COVERAGE 2. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::and → KILLED |
return new FluentCondition<>(new AndCondition<>(conditions)); |
| 98 | } | |
| 99 | ||
| 100 | /** | |
| 101 | * And operator between the provided conditions. It is a helper method that | |
| 102 | * is useful when you need to construct conditions separately: | |
| 103 | * | |
| 104 | * <pre> | |
| 105 | * List<Condition<Message>> conditions = new ArrayList<>(); | |
| 106 | * conditions.add(requiredClass("javax.mail.Transport")); | |
| 107 | * conditions.add(requiredClass("foo.Bar")); | |
| 108 | * | |
| 109 | * and(conditions); | |
| 110 | * </pre> | |
| 111 | * | |
| 112 | * Means that the result will be true only if | |
| 113 | * <code>javax.mail.Transport</code> and <code>foo.Bar</code> classes are | |
| 114 | * present in the classpath. | |
| 115 | * | |
| 116 | * <p> | |
| 117 | * If one of the condition result is false, then other conditions are not | |
| 118 | * evaluated. | |
| 119 | * </p> | |
| 120 | * | |
| 121 | * @param conditions | |
| 122 | * one or several conditions | |
| 123 | * @param <T> | |
| 124 | * the type of the object that is under condition | |
| 125 | * @return the fluent condition | |
| 126 | */ | |
| 127 | public static <T> FluentCondition<T> and(List<Condition<T>> conditions) { | |
| 128 |
2
1. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::and → NO_COVERAGE 2. and : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::and → KILLED |
return new FluentCondition<>(new AndCondition<>(conditions)); |
| 129 | } | |
| 130 | ||
| 131 | /** | |
| 132 | * Or operator between the provided conditions: | |
| 133 | * | |
| 134 | * <pre> | |
| 135 | * or(requiredClass("javax.mail.Transport"), requiredClass("foo.Bar")); | |
| 136 | * </pre> | |
| 137 | * | |
| 138 | * Means that the result will be true if either | |
| 139 | * <code>javax.mail.Transport</code> or <code>foo.Bar</code> class is | |
| 140 | * present in the classpath. | |
| 141 | * | |
| 142 | * <p> | |
| 143 | * If one of the condition result is true, then other conditions are not | |
| 144 | * evaluated. | |
| 145 | * </p> | |
| 146 | * | |
| 147 | * @param conditions | |
| 148 | * one or several conditions | |
| 149 | * @param <T> | |
| 150 | * the type of the object that is under condition | |
| 151 | * @return the fluent condition | |
| 152 | */ | |
| 153 | @SafeVarargs | |
| 154 | public static <T> FluentCondition<T> or(Condition<T>... conditions) { | |
| 155 |
2
1. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::or → NO_COVERAGE 2. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::or → KILLED |
return new FluentCondition<>(new OrCondition<>(conditions)); |
| 156 | } | |
| 157 | ||
| 158 | /** | |
| 159 | * Or operator between the provided conditions. It is a helper method that | |
| 160 | * is useful when you need to construct conditions separately: | |
| 161 | * | |
| 162 | * <pre> | |
| 163 | * List<Condition<Message>> conditions = new ArrayList<>(); | |
| 164 | * conditions.add(requiredClass("javax.mail.Transport")); | |
| 165 | * conditions.add(requiredClass("foo.Bar")); | |
| 166 | * | |
| 167 | * or(conditions); | |
| 168 | * </pre> | |
| 169 | * | |
| 170 | * Means that the result will be true if either | |
| 171 | * <code>javax.mail.Transport</code> or <code>foo.Bar</code> class is | |
| 172 | * present in the classpath. | |
| 173 | * | |
| 174 | * <p> | |
| 175 | * If one of the condition result is true, then other conditions are not | |
| 176 | * evaluated. | |
| 177 | * </p> | |
| 178 | * | |
| 179 | * @param conditions | |
| 180 | * one or several conditions | |
| 181 | * @param <T> | |
| 182 | * the type of the object that is under condition | |
| 183 | * @return the fluent condition | |
| 184 | */ | |
| 185 | public static <T> FluentCondition<T> or(List<Condition<T>> conditions) { | |
| 186 |
6
1. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::or → NO_COVERAGE 2. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::or → KILLED 3. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::or → KILLED 4. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::or → KILLED 5. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::or → KILLED 6. or : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::or → KILLED |
return new FluentCondition<>(new OrCondition<>(conditions)); |
| 187 | } | |
| 188 | ||
| 189 | /** | |
| 190 | * Not operator to reverse provided condition: | |
| 191 | * | |
| 192 | * <pre> | |
| 193 | * not(requiredClass("javax.mail.Transport)); | |
| 194 | * </pre> | |
| 195 | * | |
| 196 | * Means that the result will be true if the class | |
| 197 | * <code>javax.mail.Transport</code> is not present in the classpath. | |
| 198 | * | |
| 199 | * @param condition | |
| 200 | * the condition to reverse | |
| 201 | * @param <T> | |
| 202 | * the type of the object that is under condition | |
| 203 | * @return the fluent condition | |
| 204 | */ | |
| 205 | public static <T> FluentCondition<T> not(Condition<T> condition) { | |
| 206 |
2
1. not : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::not → NO_COVERAGE 2. not : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::not → KILLED |
return new FluentCondition<>(new NotCondition<>(condition)); |
| 207 | } | |
| 208 | ||
| 209 | /** | |
| 210 | * Check if a property is present in the configuration properties. The | |
| 211 | * configuration properties are available through the property resolver. | |
| 212 | * | |
| 213 | * <pre> | |
| 214 | * requiredProperty(propertyResolver, "mail.host"); | |
| 215 | * </pre> | |
| 216 | * | |
| 217 | * Means that the result will be true only if the property | |
| 218 | * <code>mail.host</code> is present in the property resolver. | |
| 219 | * | |
| 220 | * @param propertyResolver | |
| 221 | * the resolver that is used to access property values | |
| 222 | * @param property | |
| 223 | * the property name | |
| 224 | * @param <T> | |
| 225 | * the type of the object that is under condition | |
| 226 | * @return the fluent condition | |
| 227 | */ | |
| 228 | public static <T> FluentCondition<T> requiredProperty(PropertyResolver propertyResolver, String property) { | |
| 229 |
6
1. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredProperty → NO_COVERAGE 2. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredProperty → KILLED 3. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredProperty → KILLED 4. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredProperty → KILLED 5. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredProperty → KILLED 6. requiredProperty : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredProperty → KILLED |
return new FluentCondition<>(new RequiredPropertyCondition<>(property, propertyResolver)); |
| 230 | } | |
| 231 | ||
| 232 | /** | |
| 233 | * Check if a property has a particular value in the configuration | |
| 234 | * properties. The configuration properties are available through the | |
| 235 | * property resolver. | |
| 236 | * | |
| 237 | * <pre> | |
| 238 | * requiredPropertyValue(propertyResolver, "mail.host", "localhost"); | |
| 239 | * </pre> | |
| 240 | * | |
| 241 | * Means that the result will be true only if the property | |
| 242 | * <code>mail.host</code> is present in the property resolver and its value | |
| 243 | * is exactly <code>localhost</code>. | |
| 244 | * | |
| 245 | * @param propertyResolver | |
| 246 | * the resolver that is used to access property values | |
| 247 | * @param property | |
| 248 | * the property name | |
| 249 | * @param value | |
| 250 | * the exact value to match | |
| 251 | * @param <T> | |
| 252 | * the type of the object that is under condition | |
| 253 | * @return the fluent condition | |
| 254 | */ | |
| 255 | public static <T> FluentCondition<T> requiredPropertyValue(PropertyResolver propertyResolver, String property, String value) { | |
| 256 |
2
1. requiredPropertyValue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredPropertyValue → NO_COVERAGE 2. requiredPropertyValue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredPropertyValue → KILLED |
return new FluentCondition<>(new PropertyValueCondition<>(property, value, propertyResolver)); |
| 257 | } | |
| 258 | ||
| 259 | /** | |
| 260 | * Check if a property value matches the pattern in the configuration | |
| 261 | * properties. The configuration properties are available through the | |
| 262 | * property resolver. | |
| 263 | * | |
| 264 | * <pre> | |
| 265 | * requiredPropertyValue(propertyResolver, "mail.host", Pattern.compile("local.*")); | |
| 266 | * </pre> | |
| 267 | * | |
| 268 | * Means that the result will be true only if the property | |
| 269 | * <code>mail.host</code> is present in the property resolver and its value | |
| 270 | * matches the pattern <code>local.*</code>. | |
| 271 | * | |
| 272 | * @param propertyResolver | |
| 273 | * the resolver that is used to access property values | |
| 274 | * @param property | |
| 275 | * the property name | |
| 276 | * @param pattern | |
| 277 | * the pattern used to check if the value matches | |
| 278 | * @param <T> | |
| 279 | * the type of the object that is under condition | |
| 280 | * @return the fluent condition | |
| 281 | */ | |
| 282 | public static <T> FluentCondition<T> requiredPropertyValue(PropertyResolver propertyResolver, String property, Pattern pattern) { | |
| 283 |
2
1. requiredPropertyValue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredPropertyValue → NO_COVERAGE 2. requiredPropertyValue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredPropertyValue → KILLED |
return new FluentCondition<>(new PropertyPatternCondition<>(property, pattern, propertyResolver)); |
| 284 | } | |
| 285 | ||
| 286 | /** | |
| 287 | * Check if a class is present in the classpath. | |
| 288 | * | |
| 289 | * <pre> | |
| 290 | * requiredClass("javax.mail.Transport"); | |
| 291 | * </pre> | |
| 292 | * | |
| 293 | * Means that the result will be true only if the class | |
| 294 | * <code>javax.mail.Transport</code> is present in the classpath. | |
| 295 | * | |
| 296 | * @param className | |
| 297 | * the class to check | |
| 298 | * @param <T> | |
| 299 | * the type of the object that is under condition | |
| 300 | * @return the fluent condition | |
| 301 | */ | |
| 302 | public static <T> FluentCondition<T> requiredClass(String className) { | |
| 303 |
2
1. requiredClass : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredClass → NO_COVERAGE 2. requiredClass : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::requiredClass → KILLED |
return new FluentCondition<>(new RequiredClassCondition<>(className)); |
| 304 | } | |
| 305 | ||
| 306 | /** | |
| 307 | * A condition that always returns true. | |
| 308 | * | |
| 309 | * @param <T> | |
| 310 | * the type of the object that is under condition | |
| 311 | * @return the fluent condition | |
| 312 | */ | |
| 313 | public static <T> FluentCondition<T> alwaysTrue() { | |
| 314 |
8
1. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysTrue → SURVIVED 2. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysTrue → NO_COVERAGE 3. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysTrue → TIMED_OUT 4. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysTrue → KILLED 5. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysTrue → KILLED 6. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysTrue → KILLED 7. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysTrue → KILLED 8. alwaysTrue : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysTrue → KILLED |
return new FluentCondition<>(new FixedCondition<>(true)); |
| 315 | } | |
| 316 | ||
| 317 | /** | |
| 318 | * A condition that always returns false. | |
| 319 | * | |
| 320 | * @param <T> | |
| 321 | * the type of the object that is under condition | |
| 322 | * @return the fluent condition | |
| 323 | */ | |
| 324 | public static <T> FluentCondition<T> alwaysFalse() { | |
| 325 |
2
1. alwaysFalse : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysFalse → NO_COVERAGE 2. alwaysFalse : replaced return value with null for fr/sii/ogham/core/condition/fluent/Conditions::alwaysFalse → KILLED |
return new FluentCondition<>(new FixedCondition<>(false)); |
| 326 | } | |
| 327 | ||
| 328 | private Conditions() { | |
| 329 | super(); | |
| 330 | } | |
| 331 | } | |
Mutations | ||
| 70 |
1.1 2.2 |
|
| 97 |
1.1 2.2 |
|
| 128 |
1.1 2.2 |
|
| 155 |
1.1 2.2 |
|
| 186 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 206 |
1.1 2.2 |
|
| 229 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 256 |
1.1 2.2 |
|
| 283 |
1.1 2.2 |
|
| 303 |
1.1 2.2 |
|
| 314 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
| 325 |
1.1 2.2 |