Skip to content

Commit

Permalink
Reformat source files to 2 space indents
Browse files Browse the repository at this point in the history
After changing the `.editorconfig` to match [Google/Angular's](https://github.com/angular/angular/blob/master/.editorconfig),
this commit reformats all the source files to use this new config.

Closes #31
  • Loading branch information
NicMcPhee committed Jan 22, 2019
1 parent 7cdd6af commit 4d9d6da
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 60 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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/
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/Hellos.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
64 changes: 33 additions & 31 deletions src/test/java/HellosTest.java
Original file line number Diff line number Diff line change
@@ -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<lines.length; ++i) {
assertTrue("Line <" + lines[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<lines.length; ++i) {
assertTrue("Line " + i + " doesn't match: lines[" + i + "] is: " + lines[i] +
" and sortedLines[" + i + "] is: " + sortedLines[i], lines[i].equals(sortedLines[i]));
}
}

@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 < lines.length; ++i) {
assertTrue("Line " + i + " doesn't match: lines[" + i + "] is: " + lines[i] +
" and sortedLines[" + i + "] is: " + sortedLines[i], lines[i].equals(sortedLines[i]));
}
}

}

0 comments on commit 4d9d6da

Please sign in to comment.