FluentEmailsAssert.java

1
package fr.sii.ogham.testing.assertion.email;
2
3
import static fr.sii.ogham.testing.assertion.util.AssertionHelper.assertThat;
4
import static fr.sii.ogham.testing.assertion.util.AssertionHelper.overrideDescription;
5
import static org.hamcrest.Matchers.lessThan;
6
7
import java.util.List;
8
9
import ogham.testing.jakarta.mail.Message;
10
11
import org.hamcrest.Matcher;
12
13
import fr.sii.ogham.testing.assertion.util.AssertionRegistry;
14
import fr.sii.ogham.testing.util.HasParent;
15
16
public class FluentEmailsAssert<P> extends HasParent<P> {
17
	/**
18
	 * The list of messages that will be used for assertions
19
	 */
20
	private final List<? extends Message> actual;
21
	/**
22
	 * Registry to register assertions
23
	 */
24
	private final AssertionRegistry registry;
25
26
27
	public FluentEmailsAssert(List<? extends Message> actual, P parent, AssertionRegistry registry) {
28
		super(parent);
29
		this.actual = actual;
30
		this.registry = registry;
31
	}
32
33
	/**
34
	 * Assertion on the number of received messages:
35
	 * 
36
	 * <pre>
37
	 * .count(is(1))
38
	 * </pre>
39
	 * 
40
	 * @param matcher
41
	 *            the assertion applied on the number of received messages
42
	 * @return the fluent API for chaining assertions on received messages
43
	 */
44
	public FluentEmailsAssert<P> count(Matcher<Integer> matcher) {
45 2 1. count : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE
2. lambda$count$0 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE
		registry.register(() -> assertThat("Received messages count", actual.size(), matcher));
46 1 1. count : replaced return value with null for fr/sii/ogham/testing/assertion/email/FluentEmailsAssert::count → NO_COVERAGE
		return this;
47
	}
48
49
	/**
50
	 * Access a particular message to write assertions for it:
51
	 * 
52
	 * <pre>
53
	 * .message(0).subject(is("foobar"))
54
	 * </pre>
55
	 * 
56
	 * You can use this method to chain several assertions on different
57
	 * messages:
58
	 * 
59
	 * <pre>
60
	 * .message(0).subject(is("foobar"))
61
	 * .and()
62
	 * .message(1).subject(is("toto"))
63
	 * </pre>
64
	 * 
65
	 * 
66
	 * @param index
67
	 *            the index of the message in the received list
68
	 * @return the fluent API for chaining assertions on received messages
69
	 */
70
	public FluentEmailAssert<FluentEmailsAssert<P>> message(int index) {
71 2 1. lambda$message$1 : removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE
2. message : removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE
		registry.register(() -> assertThat(index, overrideDescription("Assertions on message "+index+" can't be executed because "+actual.size()+" messages were received", lessThan(actual.size()))));
72 3 1. message : negated conditional → NO_COVERAGE
2. message : replaced return value with null for fr/sii/ogham/testing/assertion/email/FluentEmailsAssert::message → NO_COVERAGE
3. message : changed conditional boundary → NO_COVERAGE
		return new FluentEmailAssert<>(index<actual.size() ? actual.get(index) : null, index, this, registry);
73
	}
74
75
	/**
76
	 * Fluent API to write assertions on every received messages. Any defined
77
	 * assertion will be applied on every message:
78
	 * 
79
	 * <pre>
80
	 * .receivedMessages().every().subject(is("foobar"))
81
	 * </pre>
82
	 * 
83
	 * Will check that subject of every message is "foobar".
84
	 * 
85
	 * <p>
86
	 * You can use this method to factorize several assertions on a message and
87
	 * then make dedicated assertions on some messages:
88
	 * 
89
	 * <pre>
90
	 * .receivedMessages().every().subject(is("foobar"))
91
	 *                    .and()
92
	 *                    .message(0).body().contentAsString(is("toto"))
93
	 * </pre>
94
	 * 
95
	 * Will check that subject of every message is "foobar" and that body of
96
	 * first received message is "toto".
97
	 * 
98
	 * @return the fluent API for chaining assertions on received messages
99
	 */
100
	public FluentEmailAssert<FluentEmailsAssert<P>> every() {
101 1 1. every : replaced return value with null for fr/sii/ogham/testing/assertion/email/FluentEmailsAssert::every → NO_COVERAGE
		return new FluentEmailAssert<>(actual, this, registry);
102
	}
103
}

Mutations

45

1.1
Location : count
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

2.2
Location : lambda$count$0
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE

46

1.1
Location : count
Killed by :
replaced return value with null for fr/sii/ogham/testing/assertion/email/FluentEmailsAssert::count → NO_COVERAGE

71

1.1
Location : lambda$message$1
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionHelper::assertThat → NO_COVERAGE

2.2
Location : message
Killed by :
removed call to fr/sii/ogham/testing/assertion/util/AssertionRegistry::register → NO_COVERAGE

72

1.1
Location : message
Killed by :
negated conditional → NO_COVERAGE

2.2
Location : message
Killed by :
replaced return value with null for fr/sii/ogham/testing/assertion/email/FluentEmailsAssert::message → NO_COVERAGE

3.3
Location : message
Killed by :
changed conditional boundary → NO_COVERAGE

101

1.1
Location : every
Killed by :
replaced return value with null for fr/sii/ogham/testing/assertion/email/FluentEmailsAssert::every → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.13.1