Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

E3 T2

  • Loading branch information...
commit b2ac51396e76d6b33213ba0a6cc309ddf518a672 1 parent 07fe560
@unclebob unclebob authored
View
7 src/cleancoderscom/DownloadLicense.java
@@ -0,0 +1,7 @@
+package cleancoderscom;
+
+public class DownloadLicense extends License {
+ public DownloadLicense(User user, Codecast codecast) {
+ super(user, codecast);
+ }
+}
View
11 src/cleancoderscom/PresentCodecastUseCase.java
@@ -5,7 +5,7 @@
import java.util.List;
public class PresentCodecastUseCase {
- private static SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/YYYY");
+ private static SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy");
public List<PresentableCodecast> presentCodecasts(User loggedInUser) {
ArrayList<PresentableCodecast> presentableCodecasts = new ArrayList<PresentableCodecast>();
@@ -16,6 +16,7 @@
cc.title = codecast.getTitle();
cc.publicationDate = dateFormat.format(codecast.getPublicationDate());
cc.isViewable = isLicensedToViewCodecast(loggedInUser, codecast);
+ cc.isDownloadable = isLicensedToDownloadCodecast(loggedInUser, codecast);
presentableCodecasts.add(cc);
}
return presentableCodecasts;
@@ -25,4 +26,12 @@ public boolean isLicensedToViewCodecast(User user, Codecast codecast) {
List<License> licenses = Context.gateway.findLicensesForUserAndCodecast(user, codecast);
return !licenses.isEmpty();
}
+
+ public boolean isLicensedToDownloadCodecast(User user, Codecast codecast) {
+ List<License> licenses = Context.gateway.findLicensesForUserAndCodecast(user, codecast);
+ for (License l : licenses)
+ if (l instanceof DownloadLicense)
+ return true;
+ return false;
+ }
}
View
9 src/cleancoderscom/PresentCodecastUseCaseTest.java
@@ -79,5 +79,14 @@ public void presentedCodecastIsViewableIfLicenseExists() throws Exception {
assertTrue(presentableCodecast.isViewable);
}
+ @Test
+ public void prestedCodecastIsDownloadableIfDownloadLicenseExists() throws Exception {
+ License downloadLicense = new DownloadLicense(user, codecast);
+ Context.gateway.save(downloadLicense);
+ List<PresentableCodecast> presentableCodecasts = useCase.presentCodecasts(user);
+ PresentableCodecast presentableCodecast = presentableCodecasts.get(0);
+ assertTrue(presentableCodecast.isDownloadable);
+ }
+
}
View
1  src/cleancoderscom/PresentableCodecast.java
@@ -4,4 +4,5 @@
public boolean isViewable;
public String title;
public String publicationDate;
+ public boolean isDownloadable;
}
View
10 src/cleancoderscom/fixtures/CodecastPresentation.java
@@ -36,9 +36,13 @@ public boolean createLicenseForViewing(String username, String codecastTitle) {
return useCase.isLicensedToViewCodecast(user, codecast);
}
- public boolean createLicenseForDownloading(String user, String codecast) {
- return false;
- }
+ public boolean createLicenseForDownloading(String username, String codecastTitle) {
+ User user = Context.gateway.findUser(username);
+ Codecast codecast = Context.gateway.findCodecastByTitle(codecastTitle);
+ License license = new License(user, codecast);
+ Context.gateway.save(license);
+ return useCase.isLicensedToDownloadCodecast(user, codecast);
+ }
public String presentationUser() {
return gateKeeper.getLoggedInUser().getUserName();
View
4 src/cleancoderscom/fixtures/GivenCodecasts.java
@@ -9,7 +9,7 @@
public class GivenCodecasts {
private String title;
private String publicationDate;
- private static SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/YYYY");
+ private static SimpleDateFormat dateFormat = new SimpleDateFormat("M/d/yyyy");
public void setTitle(String title) {
this.title = title;
@@ -22,6 +22,8 @@ public void setPublished(String publicationDate) {
public void execute() throws ParseException {
Codecast codecast = new Codecast();
codecast.setTitle(title);
+ System.out.println(publicationDate);
+ System.out.println(dateFormat.parse(publicationDate));
codecast.setPublicationDate(dateFormat.parse(publicationDate));
Context.gateway.save(codecast);
}
View
15 src/cleancoderscom/fixtures/OfCodeCasts.java
@@ -20,18 +20,19 @@
List<PresentableCodecast> presentableCodecasts = useCase.presentCodecasts(loggedInUser);
List<Object> queryResponse = new ArrayList<Object>();
for (PresentableCodecast pcc : presentableCodecasts)
- queryResponse.add(makeRow(pcc.title, pcc.title, pcc.title, pcc.isViewable, false));
+ queryResponse.add(makeRow(pcc));
return queryResponse;
}
- private List<Object> makeRow(String title, String picture, String description, boolean viewable, boolean downloadable) {
+ private List<Object> makeRow(PresentableCodecast pc) {
return list(
- new Object[]{list("title", title),
- list("picture", picture),
- list("description", description),
- list("viewable", viewable ? "+" : "-"),
- list("downloadable", downloadable ? "+" : "-")}
+ new Object[]{list("title", pc.title),
+ list("publication date", pc.publicationDate),
+ list("picture", pc.title),
+ list("description", pc.title),
+ list("viewable", pc.isViewable ? "+" : "-"),
+ list("downloadable", false ? "+" : "-")}
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.