@ -1,38 +0,0 @@ | |||||
package ksiazka.kucharska; | |||||
import junit.framework.Test; | |||||
import junit.framework.TestCase; | |||||
import junit.framework.TestSuite; | |||||
/** | |||||
* Unit test for simple App. | |||||
*/ | |||||
public class AppTest | |||||
extends TestCase | |||||
{ | |||||
/** | |||||
* Create the test case | |||||
* | |||||
* @param testName name of the test case | |||||
*/ | |||||
public AppTest( String testName ) | |||||
{ | |||||
super( testName ); | |||||
} | |||||
/** | |||||
* @return the suite of tests being tested | |||||
*/ | |||||
public static Test suite() | |||||
{ | |||||
return new TestSuite( AppTest.class ); | |||||
} | |||||
/** | |||||
* Rigourous Test :-) | |||||
*/ | |||||
public void testApp() | |||||
{ | |||||
assertTrue( true ); | |||||
} | |||||
} |
@ -0,0 +1,23 @@ | |||||
package ksiazka.kucharska; | |||||
import static org.junit.Assert.*; | |||||
import ksiazka.kucharska.CB_View; | |||||
import org.junit.Test; | |||||
public class RecipeBuilderTest { | |||||
@Test | |||||
public void testBuildRecipe() { | |||||
CB_View theView = new CB_View(); | |||||
RecipeManager rm = new RecipeManager(); | |||||
rm.setRecipeBuilder(new ExampleRecipeBuilder(theView)); | |||||
rm.constructRecipe(); | |||||
CB_Model obj = rm.getRecipe(); | |||||
assertEquals("Kanapka", obj.getName()); | |||||
} | |||||
} |
@ -0,0 +1,69 @@ | |||||
package ksiazka.kucharska; | |||||
import static org.junit.Assert.*; | |||||
import java.io.File; | |||||
import java.util.List; | |||||
import ksiazka.kucharska.CB_View; | |||||
import org.junit.AfterClass; | |||||
import org.junit.BeforeClass; | |||||
import org.junit.Test; | |||||
import db.Cookbook; | |||||
import db.SearchRecipe; | |||||
import db.SearchRecipeAll; | |||||
public class SearchTest { | |||||
@BeforeClass | |||||
public static void addExamples() | |||||
{ | |||||
File f1 = new File("cookbook.db"); | |||||
File f2 = new File("cookbook-bkp.db"); | |||||
if (f1.exists()) | |||||
f1.renameTo(f2); | |||||
Cookbook myCb = new Cookbook(); | |||||
CB_View theView = new CB_View(); | |||||
RecipeManager rm = new RecipeManager(); | |||||
rm.setRecipeBuilder(new ExampleRecipeBuilder(theView)); | |||||
rm.constructRecipe(); | |||||
CB_Model obj = rm.getRecipe(); | |||||
myCb.insertRecipe(obj); | |||||
myCb.insertRecipe(obj); | |||||
myCb.closeConnection(); | |||||
} | |||||
@Test | |||||
public void testSearch() { | |||||
CB_View theView = new CB_View(); | |||||
Cookbook myCb = new Cookbook(); | |||||
SearchRecipe sr; | |||||
sr = new SearchRecipeAll(theView); | |||||
List<String> names = sr.obtainRecipeNames(); | |||||
myCb.closeConnection(); | |||||
assertEquals(2, names.size()); | |||||
} | |||||
@AfterClass | |||||
public static void delExamples() | |||||
{ | |||||
Cookbook myCb = new Cookbook(); | |||||
myCb.deleteRecipe("Kanapka"); | |||||
myCb.closeConnection(); | |||||
File f1 = new File("cookbook.db"); | |||||
File f2 = new File("cookbook-bkp.db"); | |||||
f1.delete(); | |||||
if (f2.exists()) | |||||
f2.renameTo(f1); | |||||
} | |||||
} |
@ -0,0 +1,74 @@ | |||||
package ksiazka.kucharska; | |||||
import static org.junit.Assert.*; | |||||
import java.io.File; | |||||
import ksiazka.kucharska.CB_View; | |||||
import org.junit.AfterClass; | |||||
import org.junit.BeforeClass; | |||||
import org.junit.Test; | |||||
import db.Cookbook; | |||||
public class ViewRecipeTest { | |||||
static CB_View theView; | |||||
static CB_Model theModel; | |||||
static CB_Controller theController; | |||||
@BeforeClass | |||||
public static void addExamples() | |||||
{ | |||||
theView = new CB_View(); | |||||
theModel = new CB_Model(); | |||||
theController = new CB_Controller(theView, theModel); | |||||
File f1 = new File("cookbook.db"); | |||||
File f2 = new File("cookbook-bkp.db"); | |||||
if (f1.exists()) | |||||
f1.renameTo(f2); | |||||
Cookbook myCb = new Cookbook(); | |||||
RecipeManager rm = new RecipeManager(); | |||||
rm.setRecipeBuilder(new ExampleRecipeBuilder(theView)); | |||||
rm.constructRecipe(); | |||||
CB_Model obj = rm.getRecipe(); | |||||
myCb.insertRecipe(obj); | |||||
theView.setRecipesListItem(obj.getName()); | |||||
myCb.closeConnection(); | |||||
} | |||||
@SuppressWarnings("static-access") | |||||
@Test | |||||
public void testView() { | |||||
theView.getRecipesList().setSelectedIndex(theView.getRecipesList().getModel().getSize()-1); | |||||
theController.fillComponents(theView.getRecipesList().getSelectedValue().toString()); | |||||
RecipeManager rm = new RecipeManager(); | |||||
rm.setRecipeBuilder(new ExampleRecipeBuilder(theView)); | |||||
rm.constructRecipe(); | |||||
CB_Model testObj = rm.getRecipe(); | |||||
assertEquals(testObj.getName(), theView.getRecipeTitle()); | |||||
assertEquals(testObj.getIngredients(), theView.getRecipeIngredients()); | |||||
assertEquals(testObj.getDescription(), theView.getRecipeDescription()); | |||||
assertEquals(testObj.getTags(), theView.getRecipeTags()); | |||||
} | |||||
@AfterClass | |||||
public static void delExamples() | |||||
{ | |||||
Cookbook myCb = new Cookbook(); | |||||
myCb.deleteRecipe("Kanapka"); | |||||
myCb.closeConnection(); | |||||
File f1 = new File("cookbook.db"); | |||||
File f2 = new File("cookbook-bkp.db"); | |||||
f1.delete(); | |||||
if (f2.exists()) | |||||
f2.renameTo(f1); | |||||
} | |||||
} |