Skip to content

Commit

Permalink
DRY refactoring -> cumbersome test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
tkaczmarzyk committed Sep 30, 2015
1 parent 9c5b72e commit da30059
Showing 1 changed file with 34 additions and 76 deletions.
110 changes: 34 additions & 76 deletions src/test/java/net/kaczmarzyk/DocumentTest.java
Expand Up @@ -21,6 +21,22 @@ public class DocumentTest {
Person bart = new Person("Bart Simpson");
Person peter = new Person("Peter Griffin");

Document submitedDocumentAuthoredByHomerWithEditorBart = document()
.withStatus(SUBMITED)
.authoredBy(homer)
.withEditor(bart)
.build();

Document rejectedDocumentAuthoredByHomer = document()
.authoredBy(homer)
.withStatus(REJECTED)
.build();

Document draftDocumentAuthoredByHomerWithEditorBart = document()
.authoredBy(homer)
.withEditor(bart)
.build();

@Test
public void newDocumentHasStatusDraft() {
Document document = document().build();
Expand All @@ -29,136 +45,78 @@ public void newDocumentHasStatusDraft() {

@Test
public void authorCanAmendContentOfADraft() {
Document document = document()
.authoredBy(homer)
.build();
draftDocumentAuthoredByHomerWithEditorBart.amend("new content", homer);

document.amend("new content", homer);

assertThat(document).hasContent("new content");
assertThat(draftDocumentAuthoredByHomerWithEditorBart).hasContent("new content");
}

@Test
public void authorCanAmendTheContentOfADraftWithoutCreatingNewRevision() {
Document document = document()
.authoredBy(homer)
.build();

document.amend("new content", homer);
draftDocumentAuthoredByHomerWithEditorBart.amend("new content", homer);

assertThat(document).hasRevisionNumber(1);
assertThat(draftDocumentAuthoredByHomerWithEditorBart).hasRevisionNumber(1);
}

@Test
public void documentCanBeAmendedOnlyByAuthor() {
Document document = document()
.authoredBy(homer)
.build();

exception.expect(IllegalArgumentException.class);

document.amend("new content", bart);
submitedDocumentAuthoredByHomerWithEditorBart.amend("new content", bart);
}

@Test
public void newRevisionIsCreatedWhenAuthorEditsARejectedDocument() {
Document document = document()
.authoredBy(homer)
.withStatus(REJECTED)
.build();

document.amend("new content", homer);
rejectedDocumentAuthoredByHomer.amend("new content", homer);

assertThat(document).hasRevisionNumber(2);
assertThat(rejectedDocumentAuthoredByHomer).hasRevisionNumber(2);
}

@Test
public void authorCanAmendContentOfARejectedDocument() {
Document document = document()
.authoredBy(homer)
.withStatus(REJECTED)
.build();
rejectedDocumentAuthoredByHomer.amend("new content", homer);

document.amend("new content", homer);

assertThat(document).hasContent("new content");
assertThat(rejectedDocumentAuthoredByHomer).hasContent("new content");
}

@Test
public void editorMayRejectSubmitedDocument() {
Document document = document()
.withStatus(SUBMITED)
.authoredBy(homer)
.withEditor(bart)
.build();

document.reject(bart);
submitedDocumentAuthoredByHomerWithEditorBart.reject(bart);

assertThat(document).hasStatus(REJECTED);
assertThat(submitedDocumentAuthoredByHomerWithEditorBart).hasStatus(REJECTED);
}

@Test
public void editorCantRejectDocumentThatHasNotBeenSubmited() {
Document document = document()
.withStatus(DRAFT)
.authoredBy(homer)
.withEditor(bart)
.build();

exception.expect(IllegalStateException.class);

document.reject(bart);
draftDocumentAuthoredByHomerWithEditorBart.reject(bart);
}

@Test
public void onlyEditorsMayRejectDocument() {
Document document = document()
.withStatus(SUBMITED)
.authoredBy(homer)
.withEditor(bart)
.build();

exception.expect(IllegalArgumentException.class);

document.reject(peter);
submitedDocumentAuthoredByHomerWithEditorBart.reject(peter);
}

@Test
public void editorMayAcceptSubmitedDocument() {
Document document = document()
.withStatus(SUBMITED)
.authoredBy(homer)
.withEditor(bart)
.build();
submitedDocumentAuthoredByHomerWithEditorBart.accept(bart);

document.accept(bart);

assertThat(document).hasStatus(ACCEPTED);
assertThat(submitedDocumentAuthoredByHomerWithEditorBart).hasStatus(ACCEPTED);
}

@Test
public void onlyEditorMayAcceptDocument() {
Document document = document()
.withStatus(SUBMITED)
.authoredBy(homer)
.withEditor(bart)
.build();

exception.expect(IllegalArgumentException.class);

document.accept(peter);
submitedDocumentAuthoredByHomerWithEditorBart.accept(peter);
}

@Test
public void editorCantAcceptDocumentThatHasNotBeenSubmited() {
Document document = document()
.withStatus(DRAFT)
.authoredBy(homer)
.withEditor(bart)
.build();

exception.expect(IllegalStateException.class);

document.accept(bart);
draftDocumentAuthoredByHomerWithEditorBart.accept(bart);
}
}

0 comments on commit da30059

Please sign in to comment.