001: /*
002: * Created on 02/12/2005 19:23:32
003: * The JForum Project
004: * http://www.jforum.net
005: */
006: package net.jforum.entities;
007:
008: import junit.framework.TestCase;
009:
010: /**
011: * @author Rafael Steil
012: * @version $Id: PoolChangesTest.java,v 1.2 2006/04/29 14:14:27 rafaelsteil Exp $
013: */
014: public class PoolChangesTest extends TestCase {
015: public void testLabelOnlyShouldHaveChanged() {
016: Poll p1 = new Poll();
017: p1.setLabel("Label");
018: p1.addOption(new PollOption(1, "Option 1", 0));
019:
020: Poll p2 = new Poll();
021: p2.setLabel("Label 2");
022: p2.addOption(new PollOption(1, "Option 1", 0));
023:
024: PollChanges changes = new PollChanges(p1, p2);
025:
026: assertTrue(changes.hasChanges());
027: assertEquals(0, changes.getChangedOptions().size());
028: assertEquals(0, changes.getDeletedOptions().size());
029: assertEquals(0, changes.getNewOptions().size());
030: }
031:
032: public void testShouldHave1Update() {
033: Poll p1 = new Poll();
034: p1.setLabel("Label");
035: p1.addOption(new PollOption(1, "Option 1", 0));
036: p1.addOption(new PollOption(2, "Option 2", 0));
037:
038: Poll p2 = new Poll();
039: p2.setLabel("Label");
040: p2.addOption(new PollOption(1, "Option 1", 0));
041: p2.addOption(new PollOption(2, "Option 2 changed", 0));
042:
043: PollChanges changes = new PollChanges(p1, p2);
044:
045: assertTrue(changes.hasChanges());
046: assertEquals(1, changes.getChangedOptions().size());
047: assertEquals(new PollOption(2, "Option 2 changed", 0), changes
048: .getChangedOptions().get(0));
049: }
050:
051: public void testShouldHave3NewOptions() {
052: Poll p1 = new Poll();
053: p1.setLabel("Label");
054: p1.addOption(new PollOption(1, "Option 1", 0));
055:
056: Poll p2 = new Poll();
057: p2.setLabel("Label");
058: p2.addOption(new PollOption(1, "Option 1", 0));
059: p2.addOption(new PollOption(2, "Option 2", 0));
060: p2.addOption(new PollOption(3, "Option 3", 0));
061: p2.addOption(new PollOption(4, "Option 4", 0));
062:
063: PollChanges changes = new PollChanges(p1, p2);
064:
065: assertTrue(changes.hasChanges());
066: assertEquals(3, changes.getNewOptions().size());
067:
068: assertEquals(new PollOption(2, "Option 2", 0), changes
069: .getNewOptions().get(0));
070: assertEquals(new PollOption(3, "Option 3", 0), changes
071: .getNewOptions().get(1));
072: assertEquals(new PollOption(4, "Option 4", 0), changes
073: .getNewOptions().get(2));
074: }
075:
076: public void testShouldHave2DeletedOptions() {
077: Poll p1 = new Poll();
078: p1.setLabel("Label");
079: p1.addOption(new PollOption(1, "Option 1", 0));
080: p1.addOption(new PollOption(2, "Option 2", 0));
081: p1.addOption(new PollOption(3, "Option 3", 0));
082: p1.addOption(new PollOption(4, "Option 4", 0));
083:
084: Poll p2 = new Poll();
085: p2.setLabel("Label");
086: p2.addOption(new PollOption(1, "Option 1", 0));
087: p2.addOption(new PollOption(2, "Option 2", 0));
088:
089: PollChanges changes = new PollChanges(p1, p2);
090:
091: assertTrue(changes.hasChanges());
092: assertEquals(2, changes.getDeletedOptions().size());
093:
094: assertEquals(new PollOption(3, "Option 3", 0), changes
095: .getDeletedOptions().get(0));
096: assertEquals(new PollOption(4, "Option 4", 0), changes
097: .getDeletedOptions().get(1));
098: }
099:
100: public void testShouldHaveNoChanges() {
101: Poll p1 = new Poll();
102: p1.setLabel("Label");
103: p1.addOption(new PollOption(1, "Option 1", 0));
104: p1.addOption(new PollOption(2, "Option 2", 0));
105:
106: Poll p2 = new Poll();
107: p2.setLabel("Label");
108: p2.addOption(new PollOption(1, "Option 1", 0));
109: p2.addOption(new PollOption(2, "Option 2", 0));
110:
111: PollChanges changes = new PollChanges(p1, p2);
112: assertFalse(changes.hasChanges());
113: }
114: }
|