govind chettiar

Greenhorn
+ Follow
since Mar 26, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by govind chettiar

Tim Cooke wrote:The most fun way to learn why this code snip is a problem for testing is to try and write the tests for it yourself. You're quite right that you can instantiate both of those classes and you can call embarkOnQuest() but how will you assert that quest.embark(); is called?



Sorry for late reply- other priorities!
I had a typo in the original post...where I said 'if I declare a RescueDamselQuest class with a zero argument constructor and a "quest" method', it should have been ' if I declare a RescueDamselQuest class with a zero argument constructor and an "embark" method'

And I would have proceeded along the lines of what Janeice said, in this embark method I would have incremented a counter.

I am trying to follow the mocking example below and making heavy weather of it, 20 years of mainframe experience doesn't translate too easily!
8 years ago
Hi,
Trying to learn Spring and not finding it exactly easy. Am looking thru the book Spring in action. Here is a piece of code from it


And this text follows

What’s more, it’d be terribly difficult to write a unit test for DamselRescuingKnight.
In such a test, you’d like to be able to assert that the quest’s embark() method
is called when the knight’s embarkOnQuest() method is called. But there’s no clear
way to accomplish that here. Unfortunately, DamselRescuingKnight will remain
untested.



I am not able to follow why there is no clear way to accomplish this and why it means it will remain untested. As I see it, if I declare a RescueDamselQuest class with a zero argument constructor and a "quest" method, I should be able to create an instance of DamselRescuingKnight and then invoke the "embarkOnQuest" method appropriately, shouldn't I?

Thanks!
8 years ago
Thanks Campbell- I posted that older link not because I'd a question (or, as we say back in India, a doubt) about calling instance methods from w/in the constructor. I was just saying that in one of the responses to that post someone had mentioned the concept of "Bind constructor parameters"- topic of my original question.

Having said which I appreciate your insight- thanks for pointing it out!

Regards
12 years ago
I think that makes sense- use the parms in the constructor calls to set the values of the member attributes. Googling on that string "bind constructor parameters" gives a lot of hits one of which is the JavaRanch site where someone mentions that it is in the "official java book"
https://coderanch.com/t/519351/java-programmer-SCJP/certification/Constructor-cannot-call-instance-method

But virtually all the hits refer to this same text where I encountered it!

Thank you!
12 years ago
Thanks for response!
I can't post a link since one needs to log on to access the training material but here I am posting the relevant transcript
Constructing and Initializing Objects
For object initialization first the memory is allocated and default values for the instance variables are assigned. Then, the instance variable initialization uses the following steps recursively:
1) Bind Constructor parameters
2) If explicit this(), call recursively, and then execute the body of the current constructor
3 more steps
12 years ago
In this ElementK training I'm doing on the section on constructors it enumerates the steps involved in constructing an object. The first step says "Bind Constructor Parameters".
Not understanding what this means I googled it and found out that it is from the Sun (Now Oracle) tutorials. Still not clear what it means. Would appreciate any insight...
12 years ago