RandomPortServerSetup.java

1
package fr.sii.ogham.testing.extension.junit.email;
2
3
import com.icegreen.greenmail.util.ServerSetup;
4
5
import fr.sii.ogham.testing.util.RandomPortUtils;
6
7
/**
8
 * Extension of {@link ServerSetup} to handle random port.
9
 * 
10
 * Range (min and max port numbers) must be specified.
11
 * 
12
 * @author Aurélien Baudet
13
 *
14
 */
15
public class RandomPortServerSetup extends ServerSetup {
16
	private final int minPort;
17
	private final int maxPort;
18
	private int currentPort;
19
20
	/**
21
	 * Initialize the range of ports for a particular protocol. It uses the
22
	 * default bind address ({@code "127.0.0.1"} defined by
23
	 * {@link ServerSetup}).
24
	 * 
25
	 * @param minPort
26
	 *            the minimum port value
27
	 * @param maxPort
28
	 *            the maximum port value
29
	 * @param protocol
30
	 *            the protocol
31
	 */
32
	public RandomPortServerSetup(int minPort, int maxPort, String protocol) {
33
		this(minPort, maxPort, null, protocol);
34
	}
35
36
	/**
37
	 * Initialize the range of ports for a particular protocol. The bind address
38
	 * is manually specified ({@code null} can be specified to use default bind
39
	 * address).
40
	 * 
41
	 * @param minPort
42
	 *            the minimum port value
43
	 * @param maxPort
44
	 *            the maximum port value
45
	 * @param bindAddress
46
	 *            the bind address
47
	 * @param protocol
48
	 *            the protocol
49
	 */
50
	public RandomPortServerSetup(int minPort, int maxPort, String bindAddress, String protocol) {
51
		super(0, bindAddress, protocol);
52
		this.minPort = minPort;
53
		this.maxPort = maxPort;
54
	}
55
56
	@Override
57
	public int getPort() {
58 3 1. getPort : negated conditional → SURVIVED
2. getPort : negated conditional → NO_COVERAGE
3. getPort : negated conditional → TIMED_OUT
		if (currentPort == 0) {
59
			currentPort = RandomPortUtils.findAvailableTcpPort(minPort, maxPort);
60
		}
61 3 1. getPort : replaced int return with 0 for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::getPort → NO_COVERAGE
2. getPort : replaced int return with 0 for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::getPort → SURVIVED
3. getPort : replaced int return with 0 for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::getPort → TIMED_OUT
		return currentPort;
62
	}
63
64
	/**
65
	 * Add possibility to reset port in order to reuse the same server instance
66
	 * and configuration on different port when restarted.
67
	 */
68
	public void resetPort() {
69
		currentPort = 0;
70
	}
71
72
	@Override
73
	public boolean equals(Object obj) {
74 1 1. equals : negated conditional → NO_COVERAGE
		if (!super.equals(obj)) {
75 1 1. equals : replaced boolean return with true for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::equals → NO_COVERAGE
			return false;
76
		}
77 1 1. equals : negated conditional → NO_COVERAGE
		if (this.getClass() != obj.getClass()) {
78 1 1. equals : replaced boolean return with true for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::equals → NO_COVERAGE
			return false;
79
		}
80
		RandomPortServerSetup other = (RandomPortServerSetup) obj;
81 2 1. equals : replaced boolean return with true for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::equals → NO_COVERAGE
2. equals : negated conditional → NO_COVERAGE
		return currentPort == other.currentPort;
82
	}
83
	
84
	@Override
85
	public int hashCode() {
86 3 1. hashCode : Replaced integer multiplication with division → NO_COVERAGE
2. hashCode : Replaced integer addition with subtraction → NO_COVERAGE
3. hashCode : replaced int return with 0 for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::hashCode → NO_COVERAGE
		return 31 * super.hashCode() + currentPort;
87
	}
88
89
}

Mutations

58

1.1
Location : getPort
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : getPort
Killed by : none
negated conditional → SURVIVED

3.3
Location : getPort
Killed by : none
negated conditional → NO_COVERAGE

61

1.1
Location : getPort
Killed by : none
replaced int return with 0 for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::getPort → TIMED_OUT

2.2
Location : getPort
Killed by : none
replaced int return with 0 for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::getPort → NO_COVERAGE

3.3
Location : getPort
Killed by : none
replaced int return with 0 for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::getPort → SURVIVED

74

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

75

1.1
Location : equals
Killed by : none
replaced boolean return with true for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::equals → NO_COVERAGE

77

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

78

1.1
Location : equals
Killed by : none
replaced boolean return with true for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::equals → NO_COVERAGE

81

1.1
Location : equals
Killed by : none
replaced boolean return with true for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::equals → NO_COVERAGE

2.2
Location : equals
Killed by : none
negated conditional → NO_COVERAGE

86

1.1
Location : hashCode
Killed by : none
Replaced integer multiplication with division → NO_COVERAGE

2.2
Location : hashCode
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

3.3
Location : hashCode
Killed by : none
replaced int return with 0 for fr/sii/ogham/testing/extension/junit/email/RandomPortServerSetup::hashCode → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT OGHAM