From f7839ab2f4e81e392182de9651e3b2a225a13a0d Mon Sep 17 00:00:00 2001 From: "gu.martinm@gmail.com" Date: Thu, 21 Aug 2014 17:14:38 +0200 Subject: [PATCH] Test-Driven Development By Example --- TDD/pom.xml | 128 +++++++++++++++ TDD/src/main/java/de/example/tdd/Dollar.java | 13 ++ TDD/src/main/java/de/example/tdd/Money.java | 5 + TDD/src/main/resources/log4j2.xml | 197 ++++++++++++++++++++++++ TDD/src/main/resources/logback.xml | 19 +++ TDD/src/test/java/de/example/tdd/MoneyTest.java | 49 ++++++ 6 files changed, 411 insertions(+) create mode 100644 TDD/pom.xml create mode 100644 TDD/src/main/java/de/example/tdd/Dollar.java create mode 100644 TDD/src/main/java/de/example/tdd/Money.java create mode 100644 TDD/src/main/resources/log4j2.xml create mode 100644 TDD/src/main/resources/logback.xml create mode 100644 TDD/src/test/java/de/example/tdd/MoneyTest.java diff --git a/TDD/pom.xml b/TDD/pom.xml new file mode 100644 index 0000000..497e5e2 --- /dev/null +++ b/TDD/pom.xml @@ -0,0 +1,128 @@ + + + 4.0.0 + de.example.tdd + tdd-by-example + jar + 1.0-SNAPSHOT + tdd-by-example + http://gumartinm.name + TDD by example + + Gustavo Martin Morcuende + http://www.gumartinm.name + + + scm:git:http://git.gumartinm.name/TDDbyExample + http://git.gumartinm.name/TDDbyExample + + + UTF-8 + + + + + + ch.qos.logback + logback-classic + 1.1.2 + + + + + + + junit + junit + 4.12-beta-1 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + ${project.build.sourceEncoding} + -Xlint:deprecation + + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.17 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + + ${project.description} + ${project.version} + ${project.organization.name} + ${project.description} + ${project.version} + ${project.organization.name} + + + + + + + diff --git a/TDD/src/main/java/de/example/tdd/Dollar.java b/TDD/src/main/java/de/example/tdd/Dollar.java new file mode 100644 index 0000000..989b1c1 --- /dev/null +++ b/TDD/src/main/java/de/example/tdd/Dollar.java @@ -0,0 +1,13 @@ +package de.example.tdd; + +public class Dollar { + int amount; + + public Dollar(final int amount) { + this.amount = amount; + } + + public void times(final int multiplier) { + amount *= multiplier; + } +} diff --git a/TDD/src/main/java/de/example/tdd/Money.java b/TDD/src/main/java/de/example/tdd/Money.java new file mode 100644 index 0000000..0b48902 --- /dev/null +++ b/TDD/src/main/java/de/example/tdd/Money.java @@ -0,0 +1,5 @@ +package de.example.tdd; + +public class Money { + +} diff --git a/TDD/src/main/resources/log4j2.xml b/TDD/src/main/resources/log4j2.xml new file mode 100644 index 0000000..2de3fd2 --- /dev/null +++ b/TDD/src/main/resources/log4j2.xml @@ -0,0 +1,197 @@ + + + + + + target/fileappender.log + target/filerandomappender.log + + + + + + + + + + + + + + + + + + + + + + + + "%d{yyyyMMddHHmmssSSS} - %-5p - [%t] - %m%n" + UTF-8 + + + + + + + "%d{yyyyMMddHHmmssSSS} - %-5p - [%t] - %m%n" + UTF-8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TDD/src/main/resources/logback.xml b/TDD/src/main/resources/logback.xml new file mode 100644 index 0000000..685c34c --- /dev/null +++ b/TDD/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + %d{yyyyMMddHHmmssSSS} - %-5p - [%t] - [%C] - %m%n + + + + + + diff --git a/TDD/src/test/java/de/example/tdd/MoneyTest.java b/TDD/src/test/java/de/example/tdd/MoneyTest.java new file mode 100644 index 0000000..d778ee9 --- /dev/null +++ b/TDD/src/test/java/de/example/tdd/MoneyTest.java @@ -0,0 +1,49 @@ +package de.example.tdd; + +import static org.junit.Assert.*; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class MoneyTest { + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + @Test + public void testMultiplication() + { + Dollar five = new Dollar(5); + five.times(2); + + assertEquals(10, five.amount); + } +} -- 2.1.4