Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather Tracker with TDD #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_161">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<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="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>dipisp-kata</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>
3 changes: 3 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8
16 changes: 16 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
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=1.8
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
10 changes: 6 additions & 4 deletions src/main/java/com/digite/kata/tracker/Emailer.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.digite.kata.tracker;

public class Emailer {
public String generateWeatherAlert(String weatherConditions) {
String alert = "It is " + weatherConditions;
public class Emailer implements Notification {

public String generateWeatherAlert(String weatherConditions)
{
String alert = "from email : It is " + weatherConditions;
return alert;
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/digite/kata/tracker/Notification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.digite.kata.tracker;

public interface Notification
{
public String generateWeatherAlert(String weatherConditions);
}
10 changes: 6 additions & 4 deletions src/main/java/com/digite/kata/tracker/Phone.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.digite.kata.tracker;

public class Phone {
public String generateWeatherAlert(String weatherConditions) {
String alert = "It is " + weatherConditions;
public class Phone implements Notification {

public String generateWeatherAlert(String weatherConditions)
{
String alert = "from phone :It is " + weatherConditions;
return alert;
}
}
}
21 changes: 11 additions & 10 deletions src/main/java/com/digite/kata/tracker/WeatherTracker.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package com.digite.kata.tracker;

import com.digite.kata.tracker.Emailer;
import com.digite.kata.tracker.Phone;

public class WeatherTracker {
String currentConditions;
Phone phone;
Emailer emailer;

public WeatherTracker() {
/*public WeatherTracker() {
phone = new Phone();
emailer = new Emailer();
}
}*/

public String setCurrentConditions(String weatherDescription, Notification a_notification)
{

public void setCurrentConditions(String weatherDescription) {
this.currentConditions = weatherDescription;
if (weatherDescription == "rainy") {
return a_notification.generateWeatherAlert(weatherDescription);

/*if (weatherDescription == "rainy") {
String alert = phone.generateWeatherAlert(weatherDescription);
System.out.print(alert);
}
if (weatherDescription == "sunny") {
String alert = emailer.generateWeatherAlert(weatherDescription);
System.out.print(alert);
}
}*/

}
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/digite/kata/workflow/HumanInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.digite.kata.workflow;

public interface HumanInterface
{
String eat();
}
14 changes: 8 additions & 6 deletions src/main/java/com/digite/kata/workflow/JuniorWorker.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.digite.kata.workflow;

public class JuniorWorker implements Worker{

public void work() {
public class JuniorWorker implements Worker, HumanInterface
{
public String work() {
// ....working
return "working";
}
public void eat() {
// ...... eating in launch break
public String eat() {
// ...... eating in lunch break
return "eating in lunch break";
}
}
}
15 changes: 12 additions & 3 deletions src/main/java/com/digite/kata/workflow/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
public class Manager {

Worker worker;
HumanInterface w_human;

public void setWorker(Worker worker) {
this.worker=worker;
}

public void setHuman(HumanInterface a_human) {
this.w_human = a_human;
}

public String manageWork() {
return worker.work();
}

public void manage() {
worker.work();
public String manageLunchBreak() {
return w_human.eat();
}
}
}
8 changes: 3 additions & 5 deletions src/main/java/com/digite/kata/workflow/RobotWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

public class RobotWorker implements Worker{

public void work() {
public String work() {
// ....working
return " BOT working";
}

public void eat() {
throw new RuntimeException();
}
}
}
10 changes: 6 additions & 4 deletions src/main/java/com/digite/kata/workflow/SuperWorker.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.digite.kata.workflow;

public class SuperWorker implements Worker{
public class SuperWorker implements Worker, HumanInterface{

public void work() {
public String work() {
//.... working much more
return "working much more";
}

public void eat() {
public String eat() {
//.... eating in launch break
return "eating in lunch break";
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/digite/kata/workflow/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public interface Worker {

void work();
void eat();
}
String work();

}
52 changes: 52 additions & 0 deletions src/test/java/JTestManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.digite.kata.workflow.*;

public class JTestManager
{
@Test
public void testJuniorWorkerWork()
{
Worker w_juniorWorker = new JuniorWorker();
Manager w_manager = new Manager();
w_manager.setWorker(w_juniorWorker);
Assertions.assertEquals(w_manager.manageWork(), "working");
}

@Test
public void testJuniorWorkerEat()
{
HumanInterface w_juniorWorker = new JuniorWorker();
Manager w_manager = new Manager();
w_manager.setHuman(w_juniorWorker);
Assertions.assertEquals(w_manager.manageLunchBreak(), "eating in lunch break");
}

@Test
public void testRobotWorkerWork()
{
Worker w_robotWorker = new RobotWorker();
Manager w_manager = new Manager();
w_manager.setWorker(w_robotWorker);
Assertions.assertEquals(w_manager.manageWork(), " BOT working");
}

@Test
public void testSuperWorkerWork()
{
Worker w_superWorker = new SuperWorker();
Manager w_manager = new Manager();
w_manager.setWorker(w_superWorker);
Assertions.assertEquals(w_manager.manageWork(), "working much more");
}

@Test
public void testSuperWorkerEat()
{
HumanInterface w_superWorker = new SuperWorker();
Manager w_manager = new Manager();
w_manager.setHuman(w_superWorker);
Assertions.assertEquals(w_manager.manageLunchBreak(), "eating in lunch break");
}
}
28 changes: 28 additions & 0 deletions src/test/java/JTestWeatherTracker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.digite.kata.tracker.Emailer;
import com.digite.kata.tracker.Notification;
import com.digite.kata.tracker.Phone;
import com.digite.kata.tracker.WeatherTracker;

public class JTestWeatherTracker
{
@Test
public void testCurrentConditionsinRainyCase()
{
Notification a_notification = new Phone();
WeatherTracker w_tracker = new WeatherTracker();
Assertions.assertEquals(w_tracker.setCurrentConditions("rainy", a_notification),"from phone :It is rainy");
}

@Test
public void testCurrentConditionsinSunnyCase()
{
Notification a_notification = new Emailer();
WeatherTracker w_tracker = new WeatherTracker();
Assertions.assertEquals(w_tracker.setCurrentConditions("sunny", a_notification),"from email : It is sunny");
}


}