SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Vinicius Boson:
I wouldn�t like to expose them JUST because i want to test them.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Ali Pope:
I liked the solution proposed with extension, but i wouldn't go for making public functionality that is not required. Defining an API is a very important task. Maybe the solution is good for a system development, but for a library/framework I wouldn't do this. Moreover exposing an API what is not functional without the context is not a good idea.
pope's 2c
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
Originally posted by Terry Mullett:
Lasse offered a solution that would look like a strategy pattern with a bit more tweaking, and if the classes that replaced those methods had package visibility I'd say you could be done.
Originally posted by Terry Mullett:
But then comes the question: are those two methods really top-level abstractions in your mind (in which case promotion to classes could make sense) or are they just pulled out into separate methods to control ugliness (in which case promotion to classes is departing from your desing intent)? The answer to this question should also tell you whether to bother testing those methods directly, or to cover them as side effects of exercising the public method.
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
Originally posted by Ali Pope:
I think the suggestion is to extend the original class and write a separate test unit class for extended one.
./pope
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
Originally posted by Vinicius Boson:
Have you ever know about junitx ?
It seems to be an extention of junit for testing private members.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Terry Mullett:
But then comes the question: are those two methods really top-level abstractions in your mind (in which case promotion to classes could make sense) or are they just pulled out into separate methods to control ugliness (in which case promotion to classes is departing from your desing intent)? The answer to this question should also tell you whether to bother testing those methods directly, or to cover them as side effects of exercising the public method.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ali Pope:
I liked the solution proposed with extension, but i wouldn't go for making public functionality that is not required. Defining an API is a very important task. Maybe the solution is good for a system development, but for a library/framework I wouldn't do this. Moreover exposing an API what is not functional without the context is not a good idea.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Well personally I find that testing helps me discover when my initial ideas weren't as good as I'd like. Perhaps the methods should be "top level abstractions", even if I didn't initially think of them that way...
Originally posted by Ali Pope:
Even if SUN packaged the unwanted functionality in com.sun I have seen a few weeks ago an interesting usage of a class contained in this package. So I do not think that package naming will solve the public API issue.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Ilja Preuss:
Yes. And it's more complicated than I like it to be.
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
But i think it should solve part of the problem because continues because in a ejb container, you are not supposed to use reflection, right ?
Originally posted by Ali Pope:
In fact I was not talking about the impossibility of running the code, but rather about the consistency of the exposed API. I am sorry to disagree on this point. I believe that OO is about encapsulation and exposed APIs, and I do not consider a solution to offer an API to unsupported functionality. I agree that leaving this outside the Javadoc will help a little, but will not conform to OO.
./pope
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
Originally posted by Ali Pope:
Why not? Everything that is related to transaction, security, etc offered by containers is related to public API and not to private, so invoking private API using reflection will not break the container offerings. Am i completely wrong?
./pope
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Vinicius Boson:
According with ejb specification, you must not use Reflection API and the compliant container is not suposed to let you do it.
Allowing it could compromise the security.
Regards,
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Jeanne Boyarsky:
Protected members are also package-private (which is another issue altogether.) So assuming the tests are in the same package, they can access the protected member. I prefer using package-private access because I have more control over the package though.
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
Originally posted by Jeanne Boyarsky:
I see no conflict with this. The tests aren't being run in the ejb container. They are just being run in the JRE/JVM. If the code is being deployed to an ejb container, the real code won't be compromised in this way. The tests don't get run in production.
Also if someone was able to use reflection on my code, they could do it regardless of whether I had tests.
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
Originally posted by Ali Pope:
a container cannot disallow Reflection.
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Originally posted by Lasse Koskela:
In theory, it could. EJB containers are free to check that the EJB classes it loads do not (directly or indirectly) utilise "illegal" classes like java.lang.reflect.*. However, none of the EJB containers out there is actually doing this and choose to simply state that developers shouldn't use Reflection instead of implementing a hard restriction.
Originally posted by Ali Pope:
Moreover, a container cannot disallow Reflection.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Lasse Koskela:
In theory, it could. EJB containers are free to check that the EJB classes it loads do not (directly or indirectly) utilise "illegal" classes like java.lang.reflect.*. However, none of the EJB containers out there is actually doing this and choose to simply state that developers shouldn't use Reflection instead of implementing a hard restriction.
Some Containers may allow the Deployer to grant more, or fewer, permissions to the enterprise bean
instances than specified in Table 19. Support for this is not required by the EJB specification. Enterprise
beans that rely on more or fewer permissions will not be portable across all EJB Containers.
SCJP 1.4 / 5.0 - SCBCD 1.3 - SCWCD 1.4 - IBM 484
Originally posted by Ali Pope:
I am sorry to disagree on this point. I believe that OO is about encapsulation and exposed APIs, and I do not consider a solution to offer an API to unsupported functionality.
I agree that leaving this outside the Javadoc will help a little, but will not conform to OO.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Encapsulation hides detailed internal specification of an object, and publishes only its external interfaces. Thus, users of an object only need to adhere to these interfaces. By encapsulation, the internal data and methods of an object can be changed without changing the way of how to use the object.
Originally posted by Ali Pope:
I am not sure what will be the usage of an unusable object interface (as we remember the methods in cause where considered unusable without a context).
Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Let�s supose that it�s necessary to validate an student�s school registration.
validateXXX is a part of the whole validateRegistragion. They don�t have a real meaning by themselves but they are complex enought to deserve to be tested.
I wouldn�t like to expose them JUST because i want to test them.
What do you suggest me to do ?
Regards,[/QB]
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1932394230/ref=jranch-20" target="_blank" rel="nofollow">JUnit Recipes: Practical Methods for Programmer Testing</a>
Books: Pragmatic Unit Testing in Java, Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
Don't get me started about those stupid light bulbs. |