Not quite sure why this is failing, worked fine on a previous class/test pair.
Test:
@Test
public void testToString() {
OrderLine o = new OrderLine("Tuna 4 pack", 399 , 2);
String toStr = o.toString();
assertTrue("The toString method should be in the standard convention format",
toStr.startsWith("OrderLine:[") &&
toStr.contains("=" + o.getId() + ", ") &&
toStr.contains("=" + o.getUnitPrice() + ", ") &&
toStr.endsWith("=" + o.getQuantity() + "]"));
}
Class Function:
public String toString()
{
return ("OrderLine:[ ID = " + id +
", UnitPrice = " + unitPrice +
", Quantity = " + quantity +
"]");
}
Apologies if the answer to this is really obvious, its been grating me for some time and I don't exactly have any fellow students I can ask for help right now.
Thanks!
I had no idea that the spaces AFTER the equals mattered as my mind just seems to have read that they were irrelevant. I only put them there for the purpose of readability (my mistake I know)
This is the rectified code oO
return ("OrderLine:[ID =" + id +
", UnitPrice =" + unitPrice +
", quantity =" + quantity +
"]");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.