jim xu

Greenhorn
+ Follow
since Nov 18, 2007
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 jim xu

I had a hard time to figure out how to do a unittest for a method. Need some help here..



So basically, I want to unittest the fetchRows method for this class (snippet stripped off a bit in order to just show the problem). The Log class is provided by vendor's API and its a final class. I can't change it. The problem is the 'e' method requires a specific device console to establish and its a native code. In unittest environment, it just throws UnsatisfiedLinkError because there isn't such device there. I am thinking to use another mock logging class to replace the Log during runtime so that it wouldn't puke. (Like a duck typing in python) But I don't know how to do this in Java.

For example, if in python, it would be something like:

16 years ago
I'd agree that 1 and 2 are far worse than 3. If a field is private and you have public method to send the field out of the object scope, that private constrain becomes just meaningless and its a bad habit. Keep private as private, provide a wrapper method (adapter design pattern) to access them is the right way to go.
16 years ago
Since the object created is Bar's object, so "this" should reference to the Bar's object. And because the method is overridden, Bar object has no visibility of Foo's show. Try change the signature of the method for foo and call it from Bar's object, you will see that it actually calls Foo's show again, in that case these two shows become just two different methods (happened to have the same name) Interesting enough is that changing the access level can also change the calling sequence.

[ March 04, 2008: Message edited by: jim xu ]
[ March 04, 2008: Message edited by: jim xu ]
16 years ago
Ah I see. Thanks!
16 years ago
I found that java does not seem to have a very reliable way to do date/time comparison. Inspect the following sample code:

You probably would think that the date/time and millis returned by these two calendar should always be the same thus the compare result should always 0, but in fact, it doesn't. Sometimes it returns 0 sometimes -1... I spent a hack of time to find out this problem in my code (due to I wasn't even thought it could be wrong)

Here is a sample output:

the second one calc'ed 1 millisecond more. So if this isn't the prefer way to compare time in Java, what should I use?

Thanks!
[ March 02, 2008: Message edited by: jim xu ]
16 years ago
In terms of the class member, protected means only the inherited classes can see those members. The package access for class is somewhat like that. Only classes inside the same package can see that class. So can we treat the default 'package access' for a class like a 'protected' class?
16 years ago