|
From: <rga...@us...> - 2002-11-10 15:00:30
|
Update of /cvsroot/csms/csms-core/src/test/src/org/fanfoot/db
In directory usw-pr-cvs1:/tmp/cvs-serv1281
Added Files:
TestPlayers.java
Log Message:
Initial creation of access classes for the database
--- NEW FILE: TestPlayers.java ---
package org.fanfoot.db;
import java.awt.AWTEvent;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.WindowEvent;
import junit.extensions.*;
import junit.framework.*;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.w3c.dom.Node;
/*
* @author rgardler
* @created 09 November 2002
*/
public class TestPlayers extends XMLTestCase {
/** Instance of tested class. */
protected Players varPlayers;
/** A non valid player ID */
protected String invalidPlayerID = "Not a valid plaer ID";
/** A valid player ID */
protected String validPlayerID = "100";
/** A non valid game ID */
protected String invalidGameID = "Not a valid game ID";
/** A valid game ID */
protected String validGameID =
"_Saturday, 9 November, 2002_Barclaycard Premiership_Arsenal_Newcastle United";
/**
* Public constructor for creating testing class.
*
*@param name Description of the Parameter
*/
public TestPlayers( String name ) {
super( name );
}// end of main(Stringp[] args)
/**
* This method is called every time before particular test
* execution. It creates new instance of tested class and it can
* perform some more actions which are necessary for performs
* tests.
*/
protected void setUp() {
XMLUnit.setIgnoreWhitespace( true );
try {
varPlayers = new org.fanfoot.db.Players();
} catch ( DBException dbe ) {
dbe.printStackTrace();
fail( "Cannot create players object" );
}
}// end of suite()
/**
* Method for testing how works original method:
* org.w3c.dom.Element getPlayer(int) from tested class
*/
public void testGetPlayer() {
Node player = null;
try {
player = varPlayers.getPlayer( invalidPlayerID );
} catch ( DBException dbe ) {
String strMessage = DBException.UNRECOGNISED_ID_MESSAGE + invalidPlayerID;
assertEquals( "Should have thrown '" + strMessage + "' exception",
strMessage, dbe.getMessage() );
}
try {
player = varPlayers.getPlayer( validPlayerID );
} catch ( DBException dbe ) {
fail( "Threw exception getting valid player: " + dbe.getMessage() );
}
assertNotNull( "We should have a player with the id 100", player );
}
public void testGetPlayerStats() {
Node playerEvents = null;
try {
playerEvents = varPlayers.getPlayerScoringEvents( invalidPlayerID, invalidGameID );
} catch ( DBException dbe ) {
String strMessage = DBException.UNRECOGNISED_ID_MESSAGE + invalidPlayerID;
assertEquals( "Should have thrown '" + strMessage + "' exception",
strMessage, dbe.getMessage() );
}
assertNull( "Should not have any Scoring events", playerEvents );
try {
playerEvents = varPlayers.getPlayerScoringEvents( validPlayerID, invalidGameID );
} catch ( DBException dbe ) {
dbe.printStackTrace();
fail( "Should not have thrown DBException" );
}
assertNull( "Should not have any Scoring events", playerEvents );
try {
playerEvents = varPlayers.getPlayerScoringEvents( validPlayerID, validGameID );
} catch ( DBException dbe ) {
dbe.printStackTrace();
fail( "Should not have thrown DBException." );
}
assertNotNull( "Should have Scoring events", playerEvents );
}
/**
* This main method is used for run tests for this class only from
* command line.
*
*@param args The command line arguments
*/
public static void main( String[] args ) {
junit.textui.TestRunner.run( suite() );
}// end of setUp()
/**
* Returns all tests which should be performed for testing class.
* By default it returns only name of testing class. Instance of
* this is then created with its constructor.
*
*@return The test suite
*/
public static Test suite() {
return new TestSuite( TestPlayers.class );
}
}
|