|
1 | 1 | import org.junit.Before;
|
2 | 2 | import org.junit.Test;
|
| 3 | + |
3 | 4 | import java.util.Arrays;
|
| 5 | + |
4 | 6 | import static org.junit.Assert.*;
|
5 | 7 |
|
6 | 8 |
|
7 | 9 | public class HellosTest {
|
8 | 10 |
|
9 |
| - String[] lines; |
| 11 | + String[] lines; |
10 | 12 |
|
11 |
| - @Before |
12 |
| - public void setUp() { |
13 |
| - String output = Hellos.generateOutput(); |
14 |
| - lines = output.split("\n"); |
15 |
| - } |
| 13 | + @Before |
| 14 | + public void setUp() { |
| 15 | + String output = Hellos.generateOutput(); |
| 16 | + lines = output.split("\n"); |
| 17 | + } |
16 | 18 |
|
17 |
| - @Test |
18 |
| - public void testLineStructure() { |
| 19 | + @Test |
| 20 | + public void testLineStructure() { |
19 | 21 |
|
20 |
| - assertEquals("Welcome line isn't correct.", Hellos.WELCOME_LINE, lines[0]); |
| 22 | + assertEquals("Welcome line isn't correct.", Hellos.WELCOME_LINE, lines[0]); |
21 | 23 |
|
22 |
| - // This regex supports unicode letters spaces, apostrophes, and hyphens |
23 |
| - // Taken from https://stackoverflow.com/questions/15805555/java-regex-to-validate-full-name-allow-only-spaces-and-letters |
24 |
| - // The pattern needs to include some name, the "says", and the single quotes... and they must speak with emphasis |
25 |
| - // as noted by the required "!" |
26 |
| - String linePattern = "[\\p{L} .'-]+ says '+[\\p{L} .'-]+!'"; |
| 24 | + // This regex supports unicode letters spaces, apostrophes, and hyphens |
| 25 | + // Taken from https://stackoverflow.com/questions/15805555/java-regex-to-validate-full-name-allow-only-spaces-and-letters |
| 26 | + // The pattern needs to include some name, the "says", and the single quotes... and they must speak with emphasis |
| 27 | + // as noted by the required "!" |
| 28 | + String linePattern = "[\\p{L} .'-]+ says '+[\\p{L} .'-]+!'"; |
27 | 29 |
|
28 |
| - for (int i=1; i<lines.length; ++i) { |
29 |
| - assertTrue("Line <" + lines[i] + "> doesn't match", lines[i].matches(linePattern)); |
30 |
| - } |
| 30 | + for (int i = 1; i < lines.length; ++i) { |
| 31 | + assertTrue("Line <" + lines[i] + "> doesn't match", lines[i].matches(linePattern)); |
31 | 32 | }
|
32 |
| - |
33 |
| - @Test |
34 |
| - public void testAlphabetization() { |
35 |
| - // Make another list that will be sorted except for the first line |
36 |
| - String output = Hellos.generateOutput(); |
37 |
| - String[] sortedLines = output.split("\n"); |
38 |
| - Arrays.sort(sortedLines, 1, sortedLines.length); |
39 |
| - |
40 |
| - // Don't check the first line since we do that elsewhere, but compare the rest to be sure |
41 |
| - // the actual list matches the sorted list |
42 |
| - for (int i=1; i<lines.length; ++i) { |
43 |
| - assertTrue("Line " + i + " doesn't match: lines[" + i + "] is: " + lines[i] + |
44 |
| - " and sortedLines[" + i + "] is: " + sortedLines[i], lines[i].equals(sortedLines[i])); |
45 |
| - } |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testAlphabetization() { |
| 37 | + // Make another list that will be sorted except for the first line |
| 38 | + String output = Hellos.generateOutput(); |
| 39 | + String[] sortedLines = output.split("\n"); |
| 40 | + Arrays.sort(sortedLines, 1, sortedLines.length); |
| 41 | + |
| 42 | + // Don't check the first line since we do that elsewhere, but compare the rest to be sure |
| 43 | + // the actual list matches the sorted list |
| 44 | + for (int i = 1; i < lines.length; ++i) { |
| 45 | + assertTrue("Line " + i + " doesn't match: lines[" + i + "] is: " + lines[i] + |
| 46 | + " and sortedLines[" + i + "] is: " + sortedLines[i], lines[i].equals(sortedLines[i])); |
46 | 47 | }
|
| 48 | + } |
47 | 49 |
|
48 | 50 | }
|
0 commit comments