• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java return value read  RSS feed

 
Joffrey Williams
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to make a Junit Test pass. My getAccountBalance() method has to read the openAccount() and openAccount(double initialAmount) method separatly. but its seems to be reading 1 at a time.

Test requirements are at botyom.






////////////////Testing Requirements////////////////


 
Zachary Griggs
Ranch Hand
Posts: 83
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, "setBalance" is a bad name for a variable. It sounds like a method name, and then you have "setSetBalance" as your method. Just remove one of the sets from each of these.


This method does nothing. And setBalance is initialized to the double 10. So, this test:


Expects that the balance will be 1.0 but it gets 10, since nothing ever changes it.


initialAmount is the passed in argument, and setBalance is the global variable. So, you are setting the argument to the global variable, then the argument goes away, so this method also does not affect the balance.


This test should be passing even though the openAccount(double) method is incorrect, because the balance variable is initialized to 10 anyways. This isn't a well written test for that reason.


This method also does nothing


This test expects the balance to be 0.0, but it's initialized to 10 and nothing ever changes it.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zachary Griggs wrote:
... So, this test:


Expects that the balance will be 1.0 but it gets 10, since nothing ever changes it.


Except:

So it will pass, no matter what the balance has been set to.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joffrey Williams wrote:My getAccountBalance() method has to read the openAccount() and openAccount(double initialAmount) method separatly. but its seems to be reading 1 at a time.

I don't know what you mean by this. Both those openAccount methods are declared to have void return value so I don't see how you can expect getAccountBalance() to "read" anything from them, whatever that's supposed to mean. 

That statement doesn't make sense even if we translate "read" to "call" because why would you have getAccountBalance() call the openAccount() methods?

Can you describe what you're expecting to see and what you think you see in different terms?

As for your tests, they are saying to me:

Test on line 6 - calling openAccount() results in a default balance of 1.0

Test on line 11 - calling openAccount(double initialAmount) results in a balance of initialAmount

Test on line 17 - calling openAccount() then immediately closeAccount() results in a balance of 0.0

These seem reasonable enough to me. It's the implementation that's being tested that looks like it was purposely written to make those tests fail. Seems like the exercise was to fix the code so that the tests pass. If that implementation was something you wrote, then it's obviously wrong, as pointed out in detail in the previous responses given.
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.. and welcome to the Ranch
 
Joffrey Williams
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I finally got a better understanding of what was needed and had to rewrite code(a little). All of the tests were provided and we had to write the code to make them pass.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!