Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/add-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
NicMcPhee committed Jan 16, 2018
2 parents 671878c + 84b86f9 commit c5a5c0b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
25 changes: 0 additions & 25 deletions program/Hellos.java

This file was deleted.

35 changes: 35 additions & 0 deletions program/umm/csci3601/Hellos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package umm.csci3601;

/**
* A simple Java program used to demonstrate merge conflicts when
* multiple people edit the same piece of code.
*/
public class Hellos {

public static final String WELCOME_LINE = "Hello, folks!";

public static void main(String[] args) {
String output = generateOutput();

System.out.println(output);
}

public static String generateOutput() {
StringBuilder builder = new StringBuilder();

builder.append(WELCOME_LINE + "\n");
builder.append(nicSaysHello());
builder.append(kkSaysHello());

return builder.toString();
}

private static String nicSaysHello() {
return "Nic says 'Hello!'\n";
}

private static String kkSaysHello() {
return "KK says 'Hello!'\n";
}

}
25 changes: 25 additions & 0 deletions tests/umm/csci3601/HellosTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package umm.csci3601;

import org.junit.jupiter.api.Test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class HellosTest {
@Test
public void testLineStructure() {
String output = Hellos.generateOutput();
String[] lines = output.split("\n");
Hellos.WELCOME_LINE.equals(lines[0]);

String linePattern = "\\w+ says 'Hello!'";

for (int i=1; i<lines.length; ++i) {
assertTrue(lines[i].matches(linePattern),
"Line <" + lines[i] + "> doesn't match");
}
}
}

0 comments on commit c5a5c0b

Please sign in to comment.