This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Test Results 4 failed tests JUnit

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been stuck on these test failures and have narrowed it down to the Order.calHandlingCharge() method. When I run and compile the program it works but I have these last 4 of 21 tests that fail in JUnit. Any thoughts? The error given is "caused an ERROR: java.lang.NullPointerException"



Any thoughts on what I can do to get it to pass the tests? I think that its not creating and instance of something that it needs for testing?

Pasted below: OrderTest.java, Order.java, ProcessOrder.java, OrderDriver.java


 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. hChargeQuantity is null. I found this out by running the code and looking at the stack trace of the failure. Try tracking the code that calls setHChargeQuantity() to see why this is the case.
 
Sheriff
Posts: 15760
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where in your code do the fields defined on lines 289 and 290 get assigned valid references to arrays? By default, these will be set to null when an object is instantiated.
 
Tom Mordon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point they do not get created/instantiated or assigned a value by anything. I thought this was ok because I'm only comparing them to another null value, but maybe they are not a null value. I will assign them a value and compare to that value.

 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic