Skip to content

Commit

Permalink
Episode 1 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
unclebob committed Apr 17, 2014
1 parent 9caa79c commit 52e99fc
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-!|script|
|with user U logged in|
|and with license for U able to view A|
|then presentation user will be U|
|then the following codecasts will be presented for U|

| Ordered query:of code casts |
| title | picture | description | viewable |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-!|script|
|given no codecasts |
|given user U |
|with user U logged in |
|and with license for U able to view A|
|then presentation user will be U |
|then the following codecasts will be presented for U |
|there will be no codecasts presented |


Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
|scenario|and with license for _ able to view _|user,codecast|
|create license for |@user| viewing |@codecast|

|scenario|then presentation user will be _|user|
|scenario|then the following codecasts will be presented for _|user|
|check|presentation user|@user|

|scenario|there will be no codecasts presented|
|check|count of codecasts presented|0|

|scenario|given user _|user|
|add user|@user|


6 changes: 4 additions & 2 deletions FitNesseRoot/CleanCoders/content.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
!define TEST_SYSTEM {slim}
!path out/production/cleancoderscom
!contents

----
!define TEST_SYSTEM {slim}
!path out/production/cleancoderscom
14 changes: 14 additions & 0 deletions src/cleancoderscom/Codecast.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cleancoderscom;

public class Codecast {
private String title;
private String publicationDate;

public void setTitle(String title) {
this.title = title;
}

public void setPublicationDate(String publicationDate) {
this.publicationDate = publicationDate;
}
}
5 changes: 5 additions & 0 deletions src/cleancoderscom/Context.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cleancoderscom;

public class Context {
public static Gateway gateway;
}
13 changes: 13 additions & 0 deletions src/cleancoderscom/GateKeeper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cleancoderscom;

public class GateKeeper {
private User loggedInUser;

public void setLoggedInUser(User loggedInUser) {
this.loggedInUser = loggedInUser;
}

public User getLoggedInUser() {
return loggedInUser;
}
}
15 changes: 15 additions & 0 deletions src/cleancoderscom/Gateway.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cleancoderscom;

import java.util.List;

public interface Gateway {
List<Codecast> findAllCodecasts();

void delete(Codecast codecast);

void save(Codecast codecast);

void save(User user);

User findUser(String username);
}
39 changes: 39 additions & 0 deletions src/cleancoderscom/MockGateway.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cleancoderscom;

import java.util.ArrayList;
import java.util.List;

public class MockGateway implements Gateway {

private List<Codecast> codecasts;
private List<User> users;

public MockGateway() {
codecasts = new ArrayList<Codecast>();
users = new ArrayList<User>();
}

public List<Codecast> findAllCodecasts() {
return codecasts;
}

public void delete(Codecast codecast) {
codecasts.remove(codecast);
}

public void save(Codecast codecast) {
codecasts.add(codecast);
}

public void save(User user) {
users.add(user);
}

public User findUser(String username) {
for (User user : users) {
if (user.getUserName().equals(username))
return user;
}
return null;
}
}
10 changes: 10 additions & 0 deletions src/cleancoderscom/PresentCodecastUseCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package cleancoderscom;

import java.util.ArrayList;
import java.util.List;

public class PresentCodecastUseCase {
public List<PresentableCodecast> presentCodecasts(User loggedInUser) {
return new ArrayList<PresentableCodecast>();
}
}
4 changes: 4 additions & 0 deletions src/cleancoderscom/PresentableCodecast.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package cleancoderscom;

public class PresentableCodecast {
}
13 changes: 13 additions & 0 deletions src/cleancoderscom/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cleancoderscom;

public class User {
private String userName;

public User(String userName) {
this.userName = userName;
}

public String getUserName() {
return userName;
}
}
36 changes: 32 additions & 4 deletions src/cleancoderscom/fixtures/CodecastPresentation.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,51 @@
package cleancoderscom.fixtures;

import cleancoderscom.*;

import java.util.ArrayList;
import java.util.List;

public class CodecastPresentation {
private PresentCodecastUseCase useCase = new PresentCodecastUseCase();
private GateKeeper gateKeeper = new GateKeeper();

public CodecastPresentation() {
Context.gateway = new MockGateway();
}

public boolean addUser(String username) {
Context.gateway.save(new User(username));
return true;
}

public boolean loginUser(String username) {
return false;
User user = Context.gateway.findUser(username);
if (user != null) {
gateKeeper.setLoggedInUser(user);
return true;
} else {
return false;
}
}

public boolean createLicenseForViewing(String user, String codecast) {
return false;
}

public String presentationUser() {
return "TILT";
return gateKeeper.getLoggedInUser().getUserName();
}

public boolean clearCodecasts() {
return false;
List<Codecast> codecasts = Context.gateway.findAllCodecasts();
for (Codecast codecast : new ArrayList<Codecast>(codecasts)) {
Context.gateway.delete(codecast);
}
return Context.gateway.findAllCodecasts().size() == 0;
}

public int countOfCodecastsPresented() {
return -1;
List<PresentableCodecast> presentations = useCase.presentCodecasts(gateKeeper.getLoggedInUser());
return presentations.size();
}
}
5 changes: 0 additions & 5 deletions src/cleancoderscom/fixtures/GIvenNoCodecasts.java

This file was deleted.

13 changes: 12 additions & 1 deletion src/cleancoderscom/fixtures/GivenCodecasts.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package cleancoderscom.fixtures;

import cleancoderscom.Codecast;
import cleancoderscom.Context;

public class GivenCodecasts {
public void setTitle(String title) {
private String title;
private String publicationDate;

public void setTitle(String title) {
this.title = title;
}

public void setPublished(String publicationDate) {
this.publicationDate = publicationDate;
}

public void execute() {
Codecast codecast = new Codecast();
codecast.setTitle(title);
codecast.setPublicationDate(publicationDate);
Context.gateway.save(codecast);
}

}
5 changes: 2 additions & 3 deletions src/cleancoderscom/fixtures/OfCodeCasts.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ private List<Object> list(Object... objects) {
}

public List<Object> query() {
return (
return
list(
list(
//list(name,value)
)
)
);
);
}
}

0 comments on commit 52e99fc

Please sign in to comment.