Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply plugin: 'java'

sourceCompatibility = 1.6
group = 'it.tug'
version = '0.1'

jar {
manifest {
def manifestClasspath = configurations.runtime.collect { it.getName() }.join(',')
attributes 'Class-Path': manifestClasspath
}
}

jar {
manifest {
attributes 'Implementation-Title': 'SinglePath', 'Implementation-Version': '0.1', 'Main-Class': 'it.tug.Main'
}
}

repositories {
mavenCentral()
}

dependencies {
testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-all:1.9.5'
}

task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
Binary file added java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions java/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu Apr 10 09:07:03 CEST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip
164 changes: 164 additions & 0 deletions java/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions java/gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions java/src/main/java/it/tug/Main/Formatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package it.tug.Main;

public class Formatter {

private Service service;

public Formatter(Service service) {
this.service = service;
}

public String doTheJob(String theInput) {
String response = service.askForPermission();
if (response == "FAIL") {
return "error";
} else if (response == "OK") {
return String.format("%s%s", theInput, theInput);
} else {
return null;
}
}

}
8 changes: 8 additions & 0 deletions java/src/main/java/it/tug/Main/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package it.tug.Main;

public class Main {

public static void main(String[] args) {
System.out.println("Run the tests, stupid!");
}
}
5 changes: 5 additions & 0 deletions java/src/main/java/it/tug/Main/Service.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package it.tug.Main;

public interface Service {
String askForPermission();
}
49 changes: 49 additions & 0 deletions java/src/test/java/it/tug/FormatterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package it.tug;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import it.tug.Main.Formatter;
import it.tug.Main.Service;

import org.junit.Before;
import org.junit.Test;

public class FormatterTest {

private Formatter sut;
private Service service;

@Before
public void setup() {
service = mock(Service.class);
sut = new Formatter(service);
}

@Test
public void shouldReturnAnErrorMessageIfServiceReturnsNull() {
when(this.service.askForPermission()).thenReturn("FAIL");

String actual = sut.doTheJob("foo");

assertEquals("error", actual);
}

@Test
public void shouldReturnAnTheStringDoubledIfServiceReturnsOK() {
when(this.service.askForPermission()).thenReturn("OK");

String actual = sut.doTheJob("foobar");

assertEquals("foobarfoobar", actual);
}

@Test
public void shouldReturnNullIfServiceRepliesDifferentlyThanOKOrFAIL() {
when(this.service.askForPermission()).thenReturn("luchino");

String actual = sut.doTheJob("foobar");

assertEquals(null, actual);
}
}