O'Reilly Forums: Chapter 9 Unitgrouptester Question - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 9 Unitgrouptester Question

#1 User is offline   CharlieGT 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 23-November 12

Posted 26 November 2012 - 05:26 PM

Hi there!

I'm having some problems with chapter 9, if anyone could help...I'm getting a classcastexception with the tester for the unitGroup class. Here's some code...

// GET ALL UNITS WITHIN A GROUP
public List getUnits()
{
List unitList = new LinkedList();
for (Iterator i = units.entrySet().iterator(); i.hasNext(); ) { //

Unit unit = (Unit)i.next();
unitList.add(unit);

}
return unitList;
}

// MY TEST METHOD...

public void testCreateUnitGroup (List unitList, List expectedOutput)
{
System.out.print("\nTest # 1: CREATE A NEW UNITGROUP FROM A LIST...");
UnitGroup testGroup = new UnitGroup(unitList);
List Output = testGroup.getUnits();

if (expectedOutput.equals(Output))
{
System.out.println("PASSED");
}
else
{
System.out.println("FAILED");
System.out.println(""+Output);
}

}

public static void main(String[] args)
{
// TEST # 1: Create a new Group

UnitGroupTester tester = new UnitGroupTester();

Unit unit1, unit2, unit3;
List unitList = new LinkedList();

unitList.add(unit1 = new Unit(10));
unitList.add(unit2 = new Unit(20));
unitList.add(unit3 = new Unit(30));

tester.testCreateUnitGroup(unitList, unitList);
}

Again, any help or orientation with this problem would be greatly appreciated :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users