Skip to content

Commit

Permalink
E3 First Tomato
Browse files Browse the repository at this point in the history
  • Loading branch information
unclebob committed May 19, 2014
1 parent be8d09d commit 07fe560
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
Expand Up @@ -11,8 +11,8 @@
|then the following codecasts will be presented for U|

| Ordered query:of code casts |
| title | picture | description | viewable | downloadable |
| C | C | C | - | -|
| A | A | A | + | - |
| B | B | B | - | -|
| title | publication date | picture | description | viewable | downloadable |
| C | | C | C | - | -|
| A | | A | A | + | - |
| B | | B | B | - | -|

8 changes: 5 additions & 3 deletions src/cleancoderscom/Codecast.java
@@ -1,22 +1,24 @@
package cleancoderscom;

import java.util.Date;

public class Codecast extends Entity {
private String title;
private String publicationDate;
private Date publicationDate = new Date();

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

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

public String getTitle() {
return title;
}

public String getPublicationDate() {
public Date getPublicationDate() {
return publicationDate;
}
}
2 changes: 1 addition & 1 deletion src/cleancoderscom/Gateway.java
Expand Up @@ -3,7 +3,7 @@
import java.util.List;

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

void delete(Codecast codecast);

Expand Down
15 changes: 10 additions & 5 deletions src/cleancoderscom/MockGateway.java
@@ -1,8 +1,6 @@
package cleancoderscom;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;

public class MockGateway implements Gateway {

Expand All @@ -16,8 +14,15 @@ public MockGateway() {
licenses = new ArrayList<License>();
}

public List<Codecast> findAllCodecasts() {
return codecasts;
public List<Codecast> findAllCodecastsSortedChronologically()
{
List<Codecast> sortedCodecasts = new ArrayList<Codecast>(codecasts);
Collections.sort(sortedCodecasts, new Comparator<Codecast>() {
public int compare(Codecast o1, Codecast o2) {
return o1.getPublicationDate().compareTo(o2.getPublicationDate());
}
});
return sortedCodecasts;
}

public void delete(Codecast codecast) {
Expand Down
7 changes: 5 additions & 2 deletions src/cleancoderscom/PresentCodecastUseCase.java
@@ -1,17 +1,20 @@
package cleancoderscom;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class PresentCodecastUseCase {
private static SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/YYYY");

public List<PresentableCodecast> presentCodecasts(User loggedInUser) {
ArrayList<PresentableCodecast> presentableCodecasts = new ArrayList<PresentableCodecast>();
List<Codecast> allCodecasts = Context.gateway.findAllCodecasts();
List<Codecast> allCodecasts = Context.gateway.findAllCodecastsSortedChronologically();
for (Codecast codecast : allCodecasts) {

PresentableCodecast cc = new PresentableCodecast();
cc.title = codecast.getTitle();
cc.publicationDate = codecast.getPublicationDate();
cc.publicationDate = dateFormat.format(codecast.getPublicationDate());
cc.isViewable = isLicensedToViewCodecast(loggedInUser, codecast);
presentableCodecasts.add(cc);
}
Expand Down
7 changes: 5 additions & 2 deletions src/cleancoderscom/PresentCodecastUseCaseTest.java
Expand Up @@ -3,6 +3,8 @@
import org.junit.Before;
import org.junit.Test;

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -53,12 +55,13 @@ public void presentingNoCodecasts() throws Exception {
@Test
public void presentOneCodecast() throws Exception {
codecast.setTitle("Some Title");
codecast.setPublicationDate("Tomorrow");
Date now = new GregorianCalendar(2014, 4, 19).getTime();
codecast.setPublicationDate(now);
List<PresentableCodecast> presentableCodecasts = useCase.presentCodecasts(user);
assertEquals(1, presentableCodecasts.size());
PresentableCodecast presentableCodecast = presentableCodecasts.get(0);
assertEquals("Some Title", presentableCodecast.title);
assertEquals("Tomorrow", presentableCodecast.publicationDate);
assertEquals("5/19/2014", presentableCodecast.publicationDate);
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/cleancoderscom/fixtures/CodecastPresentation.java
Expand Up @@ -45,11 +45,11 @@ public String presentationUser() {
}

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

public int countOfCodecastsPresented() {
Expand Down
8 changes: 6 additions & 2 deletions src/cleancoderscom/fixtures/GivenCodecasts.java
Expand Up @@ -3,9 +3,13 @@
import cleancoderscom.Codecast;
import cleancoderscom.Context;

import java.text.ParseException;
import java.text.SimpleDateFormat;

public class GivenCodecasts {
private String title;
private String publicationDate;
private static SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/YYYY");

public void setTitle(String title) {
this.title = title;
Expand All @@ -15,10 +19,10 @@ public void setPublished(String publicationDate) {
this.publicationDate = publicationDate;
}

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

Expand Down

0 comments on commit 07fe560

Please sign in to comment.