1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
package com.explodingpixels.macwidgets;
import org.junit.Assert;
import org.junit.Test;
public class TSourceListModel {
@Test
public void testCategoryAddedAndRemoved() {
SourceListModel model = new SourceListModel();
TrackingSourceListModelListener listener = new TrackingSourceListModelListener();
model.addSourceListModelListener(listener);
// create and add the category.
SourceListCategory category = new SourceListCategory("Category");
model.addCategory(category);
// assert that we were notified of the event with the correct data.
Assert.assertTrue("categoryAdded should have been called.",
listener.wasCategoryAddedCalled());
Assert.assertEquals("The wrong category was indicated as the category added.",
category, listener.getCategoryAddedOrRemoved());
listener.reset();
// remove the category.
model.removeCategory(category);
// assert that we were notified of the event with the correct data.
Assert.assertTrue("categoryRemoved should have been called.",
listener.wasCategoryRemovedCalled());
Assert.assertEquals("The wrong category was indicated as the category removed.",
category, listener.getCategoryAddedOrRemoved());
}
@Test
public void testItemAddedAndRemovedFromCategory() {
SourceListModel model = new SourceListModel();
// create and add the category .
SourceListCategory category = new SourceListCategory("Category");
model.addCategory(category);
// create and add the SourceListModelListener.
TrackingSourceListModelListener listener = new TrackingSourceListModelListener();
model.addSourceListModelListener(listener);
// create and add the item.
SourceListItem item = new SourceListItem("Item");
model.addItemToCategory(item, category);
// assert that we were notified of the event with the correct data.
Assert.assertTrue("itemAddedToCategory should have been called.",
listener.wasItemAddedToCategoryCalled());
Assert.assertEquals("The wrong item was indicated as the item added.",
item, listener.getItemAddedOrRemoved());
Assert.assertEquals("The wrong category was indicated as the category added to.",
category, listener.getCategoryAddedToOrRemovedFrom());
listener.reset();
// remove the item.
model.removeItemFromCategory(item, category);
// assert that we were notified of the event with the correct data.
Assert.assertTrue("itemRemovedFromCategory should have been called.",
listener.wasItemRemovedFromCategoryCalled());
Assert.assertEquals("The wrong item was indicated as the item removed.",
item, listener.getItemAddedOrRemoved());
Assert.assertEquals("The wrong category was indicated as the category removed from.",
category, listener.getCategoryAddedToOrRemovedFrom());
}
@Test
public void testItemAddedAndRemovedFromItem() {
SourceListModel model = new SourceListModel();
// create and add a category and item.
SourceListCategory category = new SourceListCategory("Category");
SourceListItem item = new SourceListItem("Item");
model.addCategory(category);
model.addItemToCategory(item, category);
// create and add the SourceListModelListener.
TrackingSourceListModelListener listener = new TrackingSourceListModelListener();
model.addSourceListModelListener(listener);
// create and add a second item.
SourceListItem itemTwo = new SourceListItem("Item");
model.addItemToItem(itemTwo, item);
// assert that we were notified of the event with the correct data.
Assert.assertTrue("itemAddedToItem should have been called.",
listener.wasItemAddedToItemCalled());
Assert.assertEquals("The wrong item was indicated as the item added.",
itemTwo, listener.getItemAddedOrRemoved());
Assert.assertEquals("The wrong item was indicated as the item added to.",
item, listener.getItemAddedToOrRemovedFrom());
listener.reset();
// remove the item.
model.removeItemFromItem(itemTwo, item);
// assert that we were notified of the event with the correct data.
Assert.assertTrue("itemRemovedFromItem should have been called.",
listener.wasItemRemovedToItemCalled());
Assert.assertEquals("The wrong item was indicated as the item removed.",
itemTwo, listener.getItemAddedOrRemoved());
Assert.assertEquals("The wrong item was indicated as the item removed from.",
item, listener.getItemAddedToOrRemovedFrom());
}
}
|