diff --git a/.travis.yml b/.travis.yml index 168312d..848345c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ language: java jdk: - - oraclejdk8 +- oraclejdk8 before_cache: - - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock +- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock cache: directories: - - $HOME/.gradle/caches/ - - $HOME/.gradle/wrapper/ \ No newline at end of file + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ diff --git a/build.gradle b/build.gradle index 70a1a8e..e156539 100644 --- a/build.gradle +++ b/build.gradle @@ -10,20 +10,20 @@ // tasks for building, running, testing, and // deploying Java applications. plugins { - id 'java' - id 'application' + id 'java' + id 'application' } // In this section you declare where to find the dependencies of your project repositories { - // Use jcenter for resolving your dependencies. - // You can declare any Maven/Ivy/file repository here. - jcenter() + // Use jcenter for resolving your dependencies. + // You can declare any Maven/Ivy/file repository here. + jcenter() } dependencies { - // Use JUnit test framework - testCompile 'junit:junit:4.12' + // Use JUnit test framework + testCompile 'junit:junit:4.12' } // Define the main class for the application diff --git a/src/main/java/Hellos.java b/src/main/java/Hellos.java index 537e31a..06983c0 100644 --- a/src/main/java/Hellos.java +++ b/src/main/java/Hellos.java @@ -4,29 +4,29 @@ */ public class Hellos { - public static final String WELCOME_LINE = "Hello, folks!"; + public static final String WELCOME_LINE = "Hello, folks!"; - public static void main(String[] args) { - String output = generateOutput(); - System.out.println(output); - } + public static void main(String[] args) { + String output = generateOutput(); + System.out.println(output); + } - public static String generateOutput() { - StringBuilder builder = new StringBuilder(); + public static String generateOutput() { + StringBuilder builder = new StringBuilder(); - builder.append(WELCOME_LINE + "\n"); - builder.append(kkSaysHello()); - builder.append(nicSaysHello()); + builder.append(WELCOME_LINE + "\n"); + builder.append(kkSaysHello()); + builder.append(nicSaysHello()); - return builder.toString(); - } + return builder.toString(); + } - private static String nicSaysHello() { - return "Nic says 'Howdy!'\n"; - } + private static String nicSaysHello() { + return "Nic says 'Howdy!'\n"; + } - private static String kkSaysHello() { - return "KK says 'Hello!'\n"; - } + private static String kkSaysHello() { + return "KK says 'Hello!'\n"; + } } diff --git a/src/test/java/HellosTest.java b/src/test/java/HellosTest.java index 413e636..733d97e 100644 --- a/src/test/java/HellosTest.java +++ b/src/test/java/HellosTest.java @@ -1,48 +1,50 @@ import org.junit.Before; import org.junit.Test; + import java.util.Arrays; + import static org.junit.Assert.*; public class HellosTest { - String[] lines; + String[] lines; - @Before - public void setUp() { - String output = Hellos.generateOutput(); - lines = output.split("\n"); - } + @Before + public void setUp() { + String output = Hellos.generateOutput(); + lines = output.split("\n"); + } - @Test - public void testLineStructure() { + @Test + public void testLineStructure() { - assertEquals("Welcome line isn't correct.", Hellos.WELCOME_LINE, lines[0]); + assertEquals("Welcome line isn't correct.", Hellos.WELCOME_LINE, lines[0]); - // This regex supports unicode letters spaces, apostrophes, and hyphens - // Taken from https://stackoverflow.com/questions/15805555/java-regex-to-validate-full-name-allow-only-spaces-and-letters - // The pattern needs to include some name, the "says", and the single quotes... and they must speak with emphasis - // as noted by the required "!" - String linePattern = "[\\p{L} .'-]+ says '+[\\p{L} .'-]+!'"; + // This regex supports unicode letters spaces, apostrophes, and hyphens + // Taken from https://stackoverflow.com/questions/15805555/java-regex-to-validate-full-name-allow-only-spaces-and-letters + // The pattern needs to include some name, the "says", and the single quotes... and they must speak with emphasis + // as noted by the required "!" + String linePattern = "[\\p{L} .'-]+ says '+[\\p{L} .'-]+!'"; - for (int i=1; i doesn't match", lines[i].matches(linePattern)); - } + for (int i = 1; i < lines.length; ++i) { + assertTrue("Line <" + lines[i] + "> doesn't match", lines[i].matches(linePattern)); } - - @Test - public void testAlphabetization() { - // Make another list that will be sorted except for the first line - String output = Hellos.generateOutput(); - String[] sortedLines = output.split("\n"); - Arrays.sort(sortedLines, 1, sortedLines.length); - - // Don't check the first line since we do that elsewhere, but compare the rest to be sure - // the actual list matches the sorted list - for (int i=1; i