Contact.java

1
package fr.sii.ogham.sms.message;
2
3
import fr.sii.ogham.core.util.EqualsBuilder;
4
import fr.sii.ogham.core.util.HashCodeBuilder;
5
6
/**
7
 * A SMS contact taht contains the following information:
8
 * <ul>
9
 * <li>The name of the contact (optional)</li>
10
 * <li>The phone number of the contact</li>
11
 * </ul>
12
 * 
13
 * @author Aurélien Baudet
14
 *
15
 */
16
public class Contact {
17
	/**
18
	 * The name of the contact
19
	 */
20
	private final String name;
21
22
	/**
23
	 * The phone number for the contact
24
	 */
25
	private PhoneNumber phoneNumber;
26
27
	/**
28
	 * Initialize the contact with its phone number as string.
29
	 * <p>
30
	 * No name is specified.
31
	 * </p>
32
	 * 
33
	 * @param phoneNumber
34
	 *            the phone number for the contact
35
	 */
36
	public Contact(String phoneNumber) {
37
		this(new PhoneNumber(phoneNumber));
38
	}
39
40
	/**
41
	 * Initialize the contact with its name and its phone number as string.
42
	 * 
43
	 * @param name
44
	 *            the name of the contact
45
	 * @param phoneNumber
46
	 *            the phone number for the contact as string
47
	 */
48
	public Contact(String name, String phoneNumber) {
49
		this(name, new PhoneNumber(phoneNumber));
50
	}
51
52
	/**
53
	 * Initialize the contact with its name and its phone number.
54
	 * <p>
55
	 * No name is specified.
56
	 * </p>
57
	 * 
58
	 * @param phoneNumber
59
	 *            the phone number for the contact
60
	 */
61
	public Contact(PhoneNumber phoneNumber) {
62
		this(null, phoneNumber);
63
	}
64
65
	/**
66
	 * Initialize the contact with its name and its phone number.
67
	 * 
68
	 * @param name
69
	 *            the name of the contact
70
	 * @param phoneNumber
71
	 *            the phone number for the contact
72
	 */
73
	public Contact(String name, PhoneNumber phoneNumber) {
74
		super();
75
		this.name = name;
76
		this.phoneNumber = phoneNumber;
77
	}
78
79
	public String getName() {
80 1 1. getName : replaced return value with "" for fr/sii/ogham/sms/message/Contact::getName → RUN_ERROR
		return name;
81
	}
82
83
	public PhoneNumber getPhoneNumber() {
84 1 1. getPhoneNumber : replaced return value with null for fr/sii/ogham/sms/message/Contact::getPhoneNumber → RUN_ERROR
		return phoneNumber;
85
	}
86
87
	public void setPhoneNumber(PhoneNumber phoneNumber) {
88
		this.phoneNumber = phoneNumber;
89
	}
90
91
92
	@Override
93
	public String toString() {
94
		StringBuilder builder = new StringBuilder();
95 2 1. toString : negated conditional → RUN_ERROR
2. toString : negated conditional → NO_COVERAGE
		if (name != null && !name.isEmpty()) {
96
			builder.append(name).append(" ");
97
		}
98
		builder.append("<").append(phoneNumber).append(">");
99 1 1. toString : replaced return value with "" for fr/sii/ogham/sms/message/Contact::toString → RUN_ERROR
		return builder.toString();
100
	}
101
102
	@Override
103
	public int hashCode() {
104 1 1. hashCode : replaced int return with 0 for fr/sii/ogham/sms/message/Contact::hashCode → RUN_ERROR
		return new HashCodeBuilder().append(name, phoneNumber).hashCode();
105
	}
106
107
	@Override
108
	public boolean equals(Object obj) {
109 2 1. equals : replaced boolean return with true for fr/sii/ogham/sms/message/Contact::equals → RUN_ERROR
2. equals : replaced boolean return with false for fr/sii/ogham/sms/message/Contact::equals → RUN_ERROR
		return new EqualsBuilder(this, obj).appendFields("name", "phoneNumber").isEqual();
110
	}
111
}

Mutations

80

1.1
Location : getName
Killed by :
replaced return value with "" for fr/sii/ogham/sms/message/Contact::getName → RUN_ERROR

84

1.1
Location : getPhoneNumber
Killed by :
replaced return value with null for fr/sii/ogham/sms/message/Contact::getPhoneNumber → RUN_ERROR

95

1.1
Location : toString
Killed by :
negated conditional → RUN_ERROR

2.2
Location : toString
Killed by :
negated conditional → NO_COVERAGE

99

1.1
Location : toString
Killed by :
replaced return value with "" for fr/sii/ogham/sms/message/Contact::toString → RUN_ERROR

104

1.1
Location : hashCode
Killed by :
replaced int return with 0 for fr/sii/ogham/sms/message/Contact::hashCode → RUN_ERROR

109

1.1
Location : equals
Killed by :
replaced boolean return with true for fr/sii/ogham/sms/message/Contact::equals → RUN_ERROR

2.2
Location : equals
Killed by :
replaced boolean return with false for fr/sii/ogham/sms/message/Contact::equals → RUN_ERROR

Active mutators

Tests examined


Report generated by PIT 1.13.1