From: Gustavo Martin Morcuende Date: Wed, 26 Nov 2014 08:14:03 +0000 (+0100) Subject: TDD examples X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=38ed396a50bb4b0510b43b66f8067af1e15a1c3c;p=JavaForFun TDD examples --- diff --git a/TDD/pom.xml b/TDD/pom.xml index 497e5e2..9dcea75 100644 --- a/TDD/pom.xml +++ b/TDD/pom.xml @@ -77,8 +77,12 @@ maven-compiler-plugin 3.1 + + 1.6 + 1.6 ${project.build.sourceEncoding} -Xlint:deprecation @@ -125,4 +129,18 @@ + + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.6 + + + diff --git a/TDD/src/main/java/de/example/tdd/AddressBook.java b/TDD/src/main/java/de/example/tdd/AddressBook.java new file mode 100644 index 0000000..b7c9215 --- /dev/null +++ b/TDD/src/main/java/de/example/tdd/AddressBook.java @@ -0,0 +1,12 @@ +package de.example.tdd; + +import java.util.List; + +public class AddressBook { + + public List getAllContacts() { + + return null; + } + +} diff --git a/TDD/src/main/java/de/example/tdd/Calculator.java b/TDD/src/main/java/de/example/tdd/Calculator.java new file mode 100644 index 0000000..e8882fc --- /dev/null +++ b/TDD/src/main/java/de/example/tdd/Calculator.java @@ -0,0 +1,15 @@ +package de.example.tdd; + +public class Calculator { + + public int sum(final int augend, final int addend) { + + return augend + addend; + } + + public int product(final int multiplicand, final int multiplicier) { + + return multiplicand * multiplicier; + } + +} diff --git a/TDD/src/main/java/de/example/tdd/Contact.java b/TDD/src/main/java/de/example/tdd/Contact.java new file mode 100644 index 0000000..6570ea7 --- /dev/null +++ b/TDD/src/main/java/de/example/tdd/Contact.java @@ -0,0 +1,5 @@ +package de.example.tdd; + +public class Contact { + +} diff --git a/TDD/src/test/java/de/example/tdd/AddressBookTest.java b/TDD/src/test/java/de/example/tdd/AddressBookTest.java new file mode 100644 index 0000000..a1d8238 --- /dev/null +++ b/TDD/src/test/java/de/example/tdd/AddressBookTest.java @@ -0,0 +1,22 @@ +package de.example.tdd; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; + +public class AddressBookTest { + + @Test + public void testGivenAndExistingAddressBookWhenRetrievingTheContactsThenListWithContacts() { + //AddressBook addressBook = new AddressBook(); + + + //List contacts = addressBook.getAllContacts(); + //int size = contacts.size(); + + // Assert + assertEquals(16, 16); + } +} diff --git a/TDD/src/test/java/de/example/tdd/CalculatorTest.java b/TDD/src/test/java/de/example/tdd/CalculatorTest.java new file mode 100644 index 0000000..8c5f54c --- /dev/null +++ b/TDD/src/test/java/de/example/tdd/CalculatorTest.java @@ -0,0 +1,44 @@ +package de.example.tdd; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class CalculatorTest { + private Calculator calculator; + + @Before + public void setUp() throws Exception { + // Arrange + calculator = new Calculator(); + } + + @Test + public void testGivenTwoNumbersWhenAddingThenResult() { + // Arrange + + + // Act + int result = calculator.sum(2, 2); + + // Assert + assertEquals(4, result); + + + // Act + result = calculator.sum(8, 8); + + // Assert + assertEquals(16, result); + } + + @Test + public void testGivenTwoNumbersWhenMultiplicationThenProduct() { + + + assertEquals(16, calculator.product(4, 4)); + + assertEquals(64, calculator.product(8, 8)); + } +}