[GitHub] commons-lang pull request: Lang 1195: Enhance MethodUtils to allow...

2016-05-26 Thread PascalSchumacher
Github user PascalSchumacher commented on the pull request:

https://github.com/apache/commons-lang/pull/141#issuecomment-221935416
  
I agree.

FieldUtils supports accessing private fields, so MethodUtils should support 
accessing private methods.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] commons-lang pull request: Lang 1195: Enhance MethodUtils to allow...

2016-05-13 Thread Derek-Ashmore
Github user Derek-Ashmore commented on the pull request:

https://github.com/apache/commons-lang/pull/141#issuecomment-219016359
  
Thanks for taking time to respond.  I should be challenged on the need 
for this.  I grant your point-- over-exposing methods is technically 
possible.  I've issues with that, however.

 From an design perspective, you should only expose fields (through 
accessors/mutators) and methods you intend to expose.  That is, that are 
being made available for use by other classes or by inheritance. 
Over-exposing methods and fields in the way you describe violates OO 
design principles.  Creating an easy way for test code to access 
privates is less of a principle breach; test classes presumably know 
exactly how a class is supposed to operate and are tightly coupled to 
that class anyway.

Why create FieldUtils?  That logic should also have been used to not 
implement the methods on FieldUtils that allow you to manipulate private 
fields. Doesn't that run into the same issue?

I don't like over-exposing fields and methods just to be able to cover 
them in testing.  I'm not alone.

Thanks for taking a look at this request and taking time to comment.  
Thanks, also, for the most interesting discussion.
Derek  
 
Please note that my email address has changed to 
derek.ashm...@dvtconsulting.com
On 5/13/2016 5:23 AM, sebbASF wrote:
>
> Note that an alternative solution for testing private methods is to 
> make them package-protected.
> (and document why they are not private!)
>
> The test code needs to access it from the same package, but that is 
> not usually a problem.
> If necessary create a public method in the same package which can be 
> used by all the test code.
> A similar approach can be used for private fields; create a 
> package-protected getter.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly or view it on GitHub 
> 
>




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] commons-lang pull request: Lang 1195: Enhance MethodUtils to allow...

2016-05-13 Thread sebbASF
Github user sebbASF commented on the pull request:

https://github.com/apache/commons-lang/pull/141#issuecomment-219006770
  
Note that an alternative solution for testing private methods is to make 
them package-protected.
(and document why they are not private!)

The test code needs to access it from the same package, but that is not 
usually a problem.
If necessary create a public method in the same package which can be used 
by all the test code.
A similar approach can be used for private fields; create a 
package-protected getter.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] commons-lang pull request: Lang 1195: Enhance MethodUtils to allow...

2016-05-13 Thread Derek-Ashmore
GitHub user Derek-Ashmore opened a pull request:

https://github.com/apache/commons-lang/pull/141

Lang 1195: Enhance MethodUtils to allow invocation of private methods

Currently, MethodUtils is restricted to finding and invoking accessible 
methods. Frequently, developers have a need to test 'private' methods. What I 
see is that they escalate access to 'protected' in order to more easily provide 
test coverage for these methods. From a design perspective, this is bad.

I propose to enhance MethodUtils so that it can easily invoke private 
methods. I'm not suggesting that developers should do this in production code, 
merely test code. Much as FieldUtils provides access to private fields via the 
'forceAccess' overload on many of its methods. I've copied a utility like this 
around for years. It would be much more convenient to simply include it with 
Commons Lang. See [LANG-1195](https://issues.apache.org/jira/browse/LANG-1195) 
for details.

I made sure that I used space indentation and tried to adhere closely to 
your standards.  I've also signed the Contributor License Agreement.

Assuming you like the enhancement, I'm willing to contribute additional 
work if you see issues with what I've done.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/Force66/commons-lang LANG-1195

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/commons-lang/pull/141.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #141


commit f53fb65535232962ccd35ba9ad66e2e4c248f92e
Author: Derek Ashmore 
Date:   2016-01-01T14:31:47Z

See LANG-1195; Enhance MethodUtils to allow invocation of private
methods

commit 4a256e62529fbc57dfb55a99e222ec3591cee7ec
Author: Derek Ashmore 
Date:   2016-05-13T09:42:32Z

See LANG-1195; Removed accidental tab indentation




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---