alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

jforum example source code file (PoolChangesTest.java)

This example jforum source code file (PoolChangesTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - jforum tags/keywords

label, option, option, poll, poll, pollchanges, pollchanges, polloption, polloption, poolchangestest, testcase

The jforum PoolChangesTest.java source code

/*
 * Created on 02/12/2005 19:23:32
 * The JForum Project
 * http://www.jforum.net
 */
package net.jforum.entities;

import junit.framework.TestCase;

/**
 * @author Rafael Steil
 * @version $Id: PoolChangesTest.java,v 1.2 2006/04/29 14:14:27 rafaelsteil Exp $
 */
public class PoolChangesTest extends TestCase
{
	public void testLabelOnlyShouldHaveChanged()
	{
		Poll p1 = new Poll();
		p1.setLabel("Label");
		p1.addOption(new PollOption(1, "Option 1", 0));
		
		Poll p2 = new Poll();
		p2.setLabel("Label 2");
		p2.addOption(new PollOption(1, "Option 1", 0));
		
		PollChanges changes = new PollChanges(p1, p2);

		assertTrue(changes.hasChanges());
		assertEquals(0, changes.getChangedOptions().size());
		assertEquals(0, changes.getDeletedOptions().size());
		assertEquals(0, changes.getNewOptions().size());
	}
	
	public void testShouldHave1Update()
	{
		Poll p1 = new Poll();
		p1.setLabel("Label");
		p1.addOption(new PollOption(1, "Option 1", 0));
		p1.addOption(new PollOption(2, "Option 2", 0));
		
		Poll p2 = new Poll();
		p2.setLabel("Label");
		p2.addOption(new PollOption(1, "Option 1", 0));
		p2.addOption(new PollOption(2, "Option 2 changed", 0));
		
		PollChanges changes = new PollChanges(p1, p2);

		assertTrue(changes.hasChanges());
		assertEquals(1, changes.getChangedOptions().size());
		assertEquals(new PollOption(2, "Option 2 changed", 0), changes.getChangedOptions().get(0));
	}
	
	public void testShouldHave3NewOptions()
	{
		Poll p1 = new Poll();
		p1.setLabel("Label");
		p1.addOption(new PollOption(1, "Option 1", 0));
		
		Poll p2 = new Poll();
		p2.setLabel("Label");
		p2.addOption(new PollOption(1, "Option 1", 0));
		p2.addOption(new PollOption(2, "Option 2", 0));
		p2.addOption(new PollOption(3, "Option 3", 0));
		p2.addOption(new PollOption(4, "Option 4", 0));
		
		PollChanges changes = new PollChanges(p1, p2);
		
		assertTrue(changes.hasChanges());
		assertEquals(3, changes.getNewOptions().size());
		
		assertEquals(new PollOption(2, "Option 2", 0), changes.getNewOptions().get(0));
		assertEquals(new PollOption(3, "Option 3", 0), changes.getNewOptions().get(1));
		assertEquals(new PollOption(4, "Option 4", 0), changes.getNewOptions().get(2));
	}
	
	public void testShouldHave2DeletedOptions()
	{
		Poll p1 = new Poll();
		p1.setLabel("Label");
		p1.addOption(new PollOption(1, "Option 1", 0));
		p1.addOption(new PollOption(2, "Option 2", 0));
		p1.addOption(new PollOption(3, "Option 3", 0));
		p1.addOption(new PollOption(4, "Option 4", 0));
		
		Poll p2 = new Poll();
		p2.setLabel("Label");
		p2.addOption(new PollOption(1, "Option 1", 0));
		p2.addOption(new PollOption(2, "Option 2", 0));
		
		PollChanges changes = new PollChanges(p1, p2);
		
		assertTrue(changes.hasChanges());
		assertEquals(2, changes.getDeletedOptions().size());
		
		assertEquals(new PollOption(3, "Option 3", 0), changes.getDeletedOptions().get(0));
		assertEquals(new PollOption(4, "Option 4", 0), changes.getDeletedOptions().get(1));
	}
	
	public void testShouldHaveNoChanges()
	{
		Poll p1 = new Poll();
		p1.setLabel("Label");
		p1.addOption(new PollOption(1, "Option 1", 0));
		p1.addOption(new PollOption(2, "Option 2", 0));
		
		Poll p2 = new Poll();
		p2.setLabel("Label");
		p2.addOption(new PollOption(1, "Option 1", 0));
		p2.addOption(new PollOption(2, "Option 2", 0));
		
		PollChanges changes = new PollChanges(p1, p2);
		assertFalse(changes.hasChanges());
	}
}

Other jforum examples (source code examples)

Here is a short list of links related to this jforum PoolChangesTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.