Skip to content

Commit

Permalink
First tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloamadeu committed Mar 15, 2020
1 parent a796721 commit 701018c
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>tdd</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=11
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# tdd
# TDD - Test Driven Development

Nowadays everyone knows that TDD asks us to create unit tests first before the production code. But this rule is only the beginning.

### The three laws of TDD

**First Law:** You should not write the production code until you have created a failure unit test.

**Second Law:** You should not write more than one unit test than is necessary to fail, and not to complicate is a failure.

**Third law:** you must not write any other production code needed to apply the current failure test.
74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.maa.app</groupId>
<artifactId>tdd</artifactId>
<version>1.0-SNAPSHOT</version>

<name>tdd</name>
<!-- FIXME change it to the project's website -->
<url>https://github.com/marceloamadeu/tdd</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.3</version>
<scope>test</scope>
</dependency>


<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
12 changes: 12 additions & 0 deletions src/main/java/com/maa/app/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.maa.app;

/**
* Hello world!
*
*/
public class App
{
public static void main( final String[] args) {
System.out.println( "Hello World!" );
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/maa/app/pilha/Stack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.maa.app.pilha;

import java.util.EmptyStackException;

public class Stack {

private Object[] elements;
private int amount = 0;

public Stack(int max) {
elements = new Object[max];
}

public boolean isEmpty() {
return amount == 0;
}

public int size() {
return amount;
}

public void stackUp(Object element) {
this.elements[amount] = element;
amount++;
}

public Object top() {
return elements[amount - 1];
}

public Object unstack() {
if (isEmpty())
throw new EmptyStackException("Unable to unstack");

Object top = top();
amount--;
return top;
}

}
20 changes: 20 additions & 0 deletions src/test/java/com/maa/app/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.maa.app;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}
11 changes: 11 additions & 0 deletions src/test/java/com/maa/app/pilha/EmptyStackException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.maa.app.pilha;

public class EmptyStackException extends RuntimeException {

private static final long serialVersionUID = 1L;

public EmptyStackException(String message) {
super(message);
}

}
53 changes: 53 additions & 0 deletions src/test/java/com/maa/app/pilha/StackTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.maa.app.pilha;

import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class StackTest {

private Stack stack;

@BeforeEach
void initializeStack() {
stack = new Stack(10);
}

@Test
void emptyStack() {
assertTrue(stack.isEmpty());
assertEquals(0, stack.size());
}


@Test
void stackElement() {
stack.stackUp("First");
assertFalse(stack.isEmpty());
assertEquals(1, stack.size());
assertEquals("First", stack.top());
}

@Test
void stackUnstackElement() {
stack.stackUp("First");
stack.stackUp("Second");
assertFalse(stack.isEmpty());
assertEquals(2, stack.size());
assertEquals("Second", stack.top());
Object unstack = stack.unstack();
assertEquals(1, stack.size());
assertEquals("First", stack.top());
assertEquals("Second", unstack);
}

@Test(expected=EmptyStackException.class )
void removeFromStack() {
stack.unstack();
}


}

0 comments on commit 701018c

Please sign in to comment.