Browse Source

Junit tests

master
Grzegorz 10 years ago
parent
commit
0ee8692ebb
3 changed files with 63 additions and 0 deletions
  1. +25
    -0
      src/main/java/test/AddRecipeTest.java
  2. +11
    -0
      src/main/java/test/AllTests.java
  3. +27
    -0
      src/main/java/test/DelRecipeTestTest.java

+ 25
- 0
src/main/java/test/AddRecipeTest.java View File

@ -0,0 +1,25 @@
package test;
import static org.junit.Assert.*;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import ksiazka.kucharska.CB_View;
import org.junit.Test;
public class AddRecipeTest {
@Test
public void testAdd() {
CB_View theView = new CB_View();
JList recipesList = theView.getRecipesList();
DefaultListModel model = (DefaultListModel) recipesList.getModel();
model.addElement("recipe1");
int last = model.getSize()-1;
String item = recipesList.getModel().getElementAt(last).toString();
assertEquals("recipe1", item);
}
}

+ 11
- 0
src/main/java/test/AllTests.java View File

@ -0,0 +1,11 @@
package test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ AddRecipeTest.class, DelRecipeTestTest.class })
public class AllTests {
}

+ 27
- 0
src/main/java/test/DelRecipeTestTest.java View File

@ -0,0 +1,27 @@
package test;
import static org.junit.Assert.*;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import ksiazka.kucharska.CB_View;
import org.junit.Test;
public class DelRecipeTestTest {
@Test
public void testDel() {
CB_View theView = new CB_View();
JList recipesList = theView.getRecipesList();
DefaultListModel model = (DefaultListModel) recipesList.getModel();
model.addElement("recipe1");
int last = model.getSize()-1;
model.addElement("recipe2");
model.remove(last);
String item = model.get(last).toString();
assertEquals("recipe2", item);
}
}

Loading…
Cancel
Save