• Post Reply Bookmark Topic Watch Topic
  • New Topic

Want to write JUnit for Order class  RSS feed

 
Sucheta Shrivastava
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have created a shopping cart with product class, LineItem class and order class. The JUnit of order class is to be created. Please write a JUnit for the methods addToCart ()  and totalCheckOutCost(). Also let me know if my Methods are framed correctly. AddToCart() method adds only the quantity if the item is already present in the ArrayList items.  And totalCheckOutCost gives the checkout cost for the  item.

Product class


LineItem class



Order class
 
Norm Radder
Rancher
Posts: 2240
28
 
Sucheta Shrivastava
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried writing the JUnit, but it is unsuccessful. please check. The first assertEquals is incorrect. it says size <3> when size is <1>. he second is correct when checked individually

 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it says size <3>

Did you try printing out the contents of the List to see what is in it?

Where is item1 defined?


Note:  The indentations of the code make it hard to read and understand.  For example: The if inside of the for statement needs to be indented.
The if statement needs {}s around the code it controls.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We may have to see more of your code to know what's happening, or you may to write an SSCCE (http://sscce.org/).
 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In NetBeans you can generate unit tests by means of editor.

I guess that Eclipse had something similar.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


'1' is the correct answer, as that's the only LineItem you add to your order at the point you get the 'size' value.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!