unit testing - Accessing method call parameters at runtime in Java -


I am trying to test a terrible method that passes through the input parameters of the other for method modification.

Instead of being trivial but I want to be able to test that, during the method, the value of the input parameter is not modified for the first method before it is the second way.

Now, I know that I can do it in the class as a public frequency variable by setting the value passed in another method, then checks that it was equal to the original value passed for the first method . However, I was thinking that it is possible to test this without changing any class code (completely external).

In abstract words, an input parameter is retrieved on a method call at runtime, with reflection, for example, in Java anyway?

EDIT: Though aspect-oriented programming would be good, I was primarily thinking whether it was possible using only the standard Java library. I do not need it in any particular way - I'm just curious. If possible, leave standard Java.

Edit # 2: The value is never set individually, so I can not use reflection to use a private variable I should have said that sorry in the original question .

If you have the possibility of injecting second class example in an object under an exam external dependency , You can duplicate it using the funny framework, then capture the passed parameters of your method.

Update

A simple example, (written from the top of my head, there is no guarantee that it is compiled and works):

  Class TestedClass {Other Class Other; Public TestedClass () {...} Public Zero Set Other (Other Class Other) {this.other = other; } Public Zero Some Laws (Paramlas Ultimate) {... other Other Method (Ultimate); ...}} ... class test class {@Test Public Zero Test () {TestedClass Test = New TestedClass (); ParamClass testParam = ... Other Class Other = Make Make (OtherClass.class); From captivity to & lt; ParamClass & gt; Capture = new capture & lt; Parama Class & gt; (); Other.otherMethod (capture); Repetition (other); Tested.setOther (other); Tested.someMethod (testParam); Verify (other); AssertThat (capture.getValue (), is (testParam)); }}    

Comments