-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
261 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
ReferenceLibrary/src/test/java/referencelibrary/ui/command/AddArticleCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package referencelibrary.ui.command; | ||
|
||
import org.junit.After; | ||
import static org.junit.Assert.assertEquals; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import referencelibrary.App; | ||
import referencelibrary.data.StubDao; | ||
import referencelibrary.io.StubIO; | ||
|
||
/** | ||
* | ||
* @author sjsarsa | ||
*/ | ||
public class AddArticleCommandTest { | ||
|
||
AddReferenceCommand addRefCmd = null; | ||
App app = null; | ||
|
||
@Before | ||
public void setUp() { | ||
this.app = new App(new StubDao()); | ||
this.addRefCmd = new AddArticleCommand(this.app, createStubIO()); | ||
} | ||
|
||
/** | ||
* Create StubIO to simulate add new inproceedings -functionality. | ||
*/ | ||
private StubIO createStubIO() { | ||
StubIO stubIo = new StubIO( | ||
"someId", | ||
"someAuthor", | ||
"someTitle", | ||
"someJournal", | ||
"someYear", | ||
"someVolume", | ||
"y", //answers: "Would you like to add some optional fields?" | ||
"a", //answers: (a)dd a field | ||
"note", | ||
"someNote" | ||
); | ||
return stubIo; //author, title, booktitle, year | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
} | ||
|
||
/** | ||
* Test of execute method, of class AddReferenceCommand. | ||
*/ | ||
@Test | ||
public void testExecute() { | ||
this.addRefCmd.execute(); //this.app.listReferences().get(1).getField("author") | ||
assertEquals("someAuthor", this.app.listReferences().get(1).getField("author")); | ||
assertEquals("someTitle", this.app.listReferences().get(1).getField("title")); | ||
assertEquals("someJournal", this.app.listReferences().get(1).getField("journal")); | ||
assertEquals("someYear", this.app.listReferences().get(1).getField("year")); | ||
assertEquals("someVolume", this.app.listReferences().get(1).getField("volume")); | ||
assertEquals("someNote", this.app.listReferences().get(1).getField("note")); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
ReferenceLibrary/src/test/java/referencelibrary/ui/command/AddBookCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package referencelibrary.ui.command; | ||
|
||
import org.junit.After; | ||
import static org.junit.Assert.assertEquals; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import referencelibrary.App; | ||
import referencelibrary.data.StubDao; | ||
import referencelibrary.io.StubIO; | ||
|
||
/** | ||
* | ||
* @author sjsarsa | ||
*/ | ||
public class AddBookCommandTest { | ||
|
||
AddReferenceCommand addRefCmd = null; | ||
App app = null; | ||
|
||
@Before | ||
public void setUp() { | ||
this.app = new App(new StubDao()); | ||
} | ||
|
||
/** | ||
* Create StubIO to simulate add new inproceedings -functionality. | ||
*/ | ||
private StubIO createStubIO() { | ||
StubIO stubIo = new StubIO( | ||
"someId", | ||
"a", | ||
"someAuthor", | ||
"someTitle", | ||
"somePublisher", | ||
"someYear", | ||
"y", //answers: "Would you like to add some optional fields?" | ||
"a", //answers: (a)dd a field | ||
"note", | ||
"someNote", | ||
"s", // just for linecoverage, testing with easyB | ||
"d" | ||
); | ||
return stubIo; //author, title, booktitle, year | ||
} | ||
|
||
private StubIO createStubIOWithEditor() { | ||
StubIO stubIo = new StubIO( | ||
"someId", | ||
"e", | ||
"someEditor", | ||
"someTitle", | ||
"somePublisher", | ||
"someYear", | ||
"n" | ||
); | ||
return stubIo; //author, title, booktitle, year | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
} | ||
|
||
/** | ||
* Test of execute method, of class AddReferenceCommand. | ||
*/ | ||
@Test | ||
public void testExecuteWithAuthorSelected() { | ||
this.addRefCmd = new AddBookCommand(this.app, createStubIO()); | ||
this.addRefCmd.execute(); //this.app.listReferences().get(1).getField("author") | ||
assertEquals("someAuthor", this.app.listReferences().get(1).getField("author")); | ||
assertEquals("someTitle", this.app.listReferences().get(1).getField("title")); | ||
assertEquals("somePublisher", this.app.listReferences().get(1).getField("publisher")); | ||
assertEquals("someYear", this.app.listReferences().get(1).getField("year")); | ||
assertEquals("someNote", this.app.listReferences().get(1).getField("note")); | ||
} | ||
|
||
@Test | ||
public void testExecuteWithEditor() { | ||
this.addRefCmd = new AddBookCommand(this.app, createStubIOWithEditor()); | ||
this.addRefCmd.execute(); //this.app.listReferences().get(1).getField("author") | ||
assertEquals("someEditor", this.app.listReferences().get(1).getField("editor")); | ||
assertEquals("someTitle", this.app.listReferences().get(1).getField("title")); | ||
assertEquals("somePublisher", this.app.listReferences().get(1).getField("publisher")); | ||
assertEquals("someYear", this.app.listReferences().get(1).getField("year")); | ||
} | ||
|
||
@Test | ||
public void testEditorOrAuthorAsObligatoryField() { | ||
this.addRefCmd = new AddBookCommand(this.app, createStubIO()); | ||
this.addRefCmd.execute(); | ||
assertEquals(null, this.app.listReferences().get(1).getField("editor")); | ||
assertEquals("someAuthor", this.app.listReferences().get(1).getField("author")); | ||
} | ||
|
||
@Test | ||
public void testEditorOrAuthorAsDefaultObligatoryField() { | ||
StubIO stubIO = new StubIO("id", "something", "someAuthor", "2", "3", "4", "n"); | ||
this.addRefCmd = new AddBookCommand(this.app, stubIO); | ||
this.addRefCmd.execute(); | ||
assertEquals(null, this.app.listReferences().get(1).getField("editor")); | ||
assertEquals("someAuthor", this.app.listReferences().get(1).getField("author")); | ||
assertEquals(true, stubIO.getPrints().contains("author selected as default")); | ||
} | ||
|
||
@Test | ||
public void testEditorAsObligatoryField() { | ||
this.addRefCmd = new AddBookCommand(this.app, new StubIO("id", "e", "someEditor", "2", "3", "4", "n")); | ||
this.addRefCmd.execute(); | ||
assertEquals(null, this.app.listReferences().get(1).getField("author")); | ||
assertEquals("someEditor", this.app.listReferences().get(1).getField("editor")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
ReferenceLibrary/src/test/java/referencelibrary/ui/command/ShowReferencesCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package referencelibrary.ui.command; | ||
|
||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
import referencelibrary.App; | ||
import referencelibrary.data.StubDao; | ||
import referencelibrary.io.StubIO; | ||
import referencelibrary.reference.BookReference; | ||
import static referencelibrary.reference.ReferenceType.REFERENCE_BOOK; | ||
|
||
/** | ||
* | ||
* @author sjsarsa | ||
*/ | ||
public class ShowReferencesCommandTest { | ||
|
||
ShowReferencesCommand showRefCmd; | ||
App app; | ||
StubIO stubIO; | ||
|
||
public ShowReferencesCommandTest() { | ||
} | ||
|
||
@BeforeClass | ||
public static void setUpClass() { | ||
} | ||
|
||
@AfterClass | ||
public static void tearDownClass() { | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
this.app = new App(new StubDao()); | ||
this.stubIO = new StubIO("s"); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
} | ||
|
||
@Test | ||
public void testExecute() { | ||
this.showRefCmd = new ShowReferencesCommand(this.app, stubIO); | ||
this.showRefCmd.execute(); | ||
assertEquals("[Book: REF]", stubIO.getPrints().get(0)); | ||
assertEquals(1, stubIO.getPrints().size()); | ||
} | ||
|
||
@Test | ||
public void testShowNewReference() { | ||
this.showRefCmd = new ShowReferencesCommand(this.app, stubIO); | ||
app.newReference(new BookReference("asdasd")); | ||
this.showRefCmd.execute(); | ||
assertEquals(true, stubIO.getPrints().contains("[Book: asdasd]")); | ||
assertEquals(2, stubIO.getPrints().size()); | ||
} | ||
|
||
|
||
|
||
} |