TDD examples
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 26 Nov 2014 08:14:03 +0000 (09:14 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 26 Nov 2014 08:14:03 +0000 (09:14 +0100)
TDD/pom.xml
TDD/src/main/java/de/example/tdd/AddressBook.java [new file with mode: 0644]
TDD/src/main/java/de/example/tdd/Calculator.java [new file with mode: 0644]
TDD/src/main/java/de/example/tdd/Contact.java [new file with mode: 0644]
TDD/src/test/java/de/example/tdd/AddressBookTest.java [new file with mode: 0644]
TDD/src/test/java/de/example/tdd/CalculatorTest.java [new file with mode: 0644]

index 497e5e2..9dcea75 100644 (file)
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.1</version>
                 <configuration>
+                                       <!--
                     <source>1.8</source>
                     <target>1.8</target>
+                                       -->
+                                       <source>1.6</source>
+                    <target>1.6</target>
                     <encoding>${project.build.sourceEncoding}</encoding>
                     <compilerArgument>-Xlint:deprecation</compilerArgument>
                 </configuration>
             </plugin>
         </plugins>
     </build>
+       <reporting>
+        <plugins>
+            <plugin>
+                               <!--
+                               <groupId>org.jacoco</groupId>
+                       <artifactId>jacoco</artifactId>
+                       <version>0.7.2.201409121644</version>
+                               -->
+                       <groupId>org.codehaus.mojo</groupId>
+                       <artifactId>cobertura-maven-plugin</artifactId>
+                       <version>2.6</version>
+                       </plugin>
+               </plugins>
+       </reporting>
 </project>
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 (file)
index 0000000..b7c9215
--- /dev/null
@@ -0,0 +1,12 @@
+package de.example.tdd;
+
+import java.util.List;
+
+public class AddressBook {
+
+       public List<Contact> 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 (file)
index 0000000..e8882fc
--- /dev/null
@@ -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 (file)
index 0000000..6570ea7
--- /dev/null
@@ -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 (file)
index 0000000..a1d8238
--- /dev/null
@@ -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<Contact> 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 (file)
index 0000000..8c5f54c
--- /dev/null
@@ -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));
+       }
+}