66import static org .junit .Assert .assertEquals ;
77
88public class PhoneNumberTest {
9- private static String wrongLengthExceptionMessage = "Number must be 10 or 11 digits" ;
9+ private static String wrongLengthExceptionMessage = "incorrect number of digits" ;
10+ private static String moreThan11DigitsExceptionMessage = "more than 11 digits" ;
1011 private static String numberIs11DigitsButDoesNotStartWith1ExceptionMessage =
11- "Can only have 11 digits if number starts with '1' " ;
12+ "11 digits must start with 1 " ;
1213 private static String illegalCharacterExceptionMessage =
13- "Illegal character in phone number. Only digits, spaces, parentheses, hyphens or dots accepted." ;
14- private static String illegalAreaOrExchangeCodeMessage =
15- "Illegal Area Or Exchange Code. Only 2-9 are valid digits" ;
16-
14+ "letters not permitted" ;
15+ private static String illegalPunctuationExceptionMessage =
16+ "punctuations not permitted" ;
17+ private static String areaCodeStartsWithZeroExceptionMessage =
18+ "area code cannot start with zero" ;
19+ private static String areaCodeStartsWithOneExceptionMessage =
20+ "area code cannot start with one" ;
21+ private static String exchangeCodeStartsWithZeroExceptionMessage =
22+ "exchange code cannot start with zero" ;
23+ private static String exchangeCodeStartsWithOneExceptionMessage =
24+ "exchange code cannot start with one" ;
25+
1726 @ Rule
1827 public ExpectedException expectedException = ExpectedException .none ();
1928
@@ -91,7 +100,7 @@ public void validWhen11DigitsAndStartingWith1EvenWithPunctuation() {
91100 @ Test
92101 public void invalidWhenMoreThan11Digits () {
93102 expectedException .expect (IllegalArgumentException .class );
94- expectedException .expectMessage (wrongLengthExceptionMessage );
103+ expectedException .expectMessage (moreThan11DigitsExceptionMessage );
95104 new PhoneNumber ("321234567890" );
96105 }
97106
@@ -107,71 +116,71 @@ public void invalidWithLetters() {
107116 @ Test
108117 public void invalidWithPunctuations () {
109118 expectedException .expect (IllegalArgumentException .class );
110- expectedException .expectMessage (illegalCharacterExceptionMessage );
119+ expectedException .expectMessage (illegalPunctuationExceptionMessage );
111120 new PhoneNumber ("123-@:!-7890" );
112121 }
113122
114123 @ Ignore ("Remove to run test" )
115124 @ Test
116125 public void invalidIfAreaCodeStartsWith0 () {
117126 expectedException .expect (IllegalArgumentException .class );
118- expectedException .expectMessage (illegalAreaOrExchangeCodeMessage );
127+ expectedException .expectMessage (areaCodeStartsWithZeroExceptionMessage );
119128 new PhoneNumber ("(023) 456-7890" );
120129 }
121130
122131 @ Ignore ("Remove to run test" )
123132 @ Test
124133 public void invalidIfAreaCodeStartsWith1 () {
125134 expectedException .expect (IllegalArgumentException .class );
126- expectedException .expectMessage (illegalAreaOrExchangeCodeMessage );
135+ expectedException .expectMessage (areaCodeStartsWithOneExceptionMessage );
127136 new PhoneNumber ("(123) 456-7890" );
128137 }
129138
130139 @ Ignore ("Remove to run test" )
131140 @ Test
132141 public void invalidIfExchangeCodeStartsWith0 () {
133142 expectedException .expect (IllegalArgumentException .class );
134- expectedException .expectMessage (illegalAreaOrExchangeCodeMessage );
143+ expectedException .expectMessage (exchangeCodeStartsWithZeroExceptionMessage );
135144 new PhoneNumber ("(223) 056-7890" );
136145 }
137146
138147 @ Ignore ("Remove to run test" )
139148 @ Test
140149 public void invalidIfExchangeCodeStartsWith1 () {
141150 expectedException .expect (IllegalArgumentException .class );
142- expectedException .expectMessage (illegalAreaOrExchangeCodeMessage );
151+ expectedException .expectMessage (exchangeCodeStartsWithOneExceptionMessage );
143152 new PhoneNumber ("(223) 156-7890" );
144153 }
145154
146155 @ Ignore ("Remove to run test" )
147156 @ Test
148157 public void invalidIfAreaCodeStartsWith0OnValid11DigitNumber () {
149158 expectedException .expect (IllegalArgumentException .class );
150- expectedException .expectMessage (illegalAreaOrExchangeCodeMessage );
159+ expectedException .expectMessage (areaCodeStartsWithZeroExceptionMessage );
151160 new PhoneNumber ("1 (023) 456-7890" );
152161 }
153162
154163 @ Ignore ("Remove to run test" )
155164 @ Test
156165 public void invalidIfAreaCodeStartsWith1OnValid11DigitNumber () {
157166 expectedException .expect (IllegalArgumentException .class );
158- expectedException .expectMessage (illegalAreaOrExchangeCodeMessage );
167+ expectedException .expectMessage (areaCodeStartsWithOneExceptionMessage );
159168 new PhoneNumber ("1 (123) 456-7890" );
160169 }
161170
162171 @ Ignore ("Remove to run test" )
163172 @ Test
164173 public void invalidIfExchangeCodeStartsWith0OnValid11DigitNumber () {
165174 expectedException .expect (IllegalArgumentException .class );
166- expectedException .expectMessage (illegalAreaOrExchangeCodeMessage );
175+ expectedException .expectMessage (exchangeCodeStartsWithZeroExceptionMessage );
167176 new PhoneNumber ("1 (223) 056-7890" );
168177 }
169178
170179 @ Ignore ("Remove to run test" )
171180 @ Test
172181 public void invalidIfExchangeCodeStartsWith1OnValid11DigitNumber () {
173182 expectedException .expect (IllegalArgumentException .class );
174- expectedException .expectMessage (illegalAreaOrExchangeCodeMessage );
183+ expectedException .expectMessage (exchangeCodeStartsWithOneExceptionMessage );
175184 new PhoneNumber ("1 (223) 156-7890" );
176185 }
177186}
0 commit comments