Hi Hadrien,
This is a pretty common problem and there are a few ways to deal with it. For testing purposes, the simplest approach is probably to encapsulate the creation of that object in a protected method and then create a sub-class of your test class for testing which overrides the method that creates the object and returns a mock:
-------------------------
this._req = this.createRequest(this._onlineResources, onSuccess, onFailure);
...
protected function createRequest(...):DataRequest {
return new DataRequest(...);
}
-------------------------
Then, you can create an inner class in your test case which overrides that behavior:
-------------------------
package {
public class SomeTest {
@Mock
public var dataRequset:DataRequest;
private var subject:YourTestSubject
@Before
public function setup() {
this.subject = new Testable(dataRequest);
}
}
}
class Testable extends YourTestSubject {
private request:DataRequest;
public Testable(request:DataRequest) {
super();
this.request = request;
}
override protected function createRequest() {
return this.request;
}
}
-------------------------
Like I said, this is only one way to accomplish this. There's the whole injection approach, but that involves integrating an injection framework like Parsley or Robotlegs. You could also create a Provider class who's job is simply to create your request instances for you, and then swap ou providers at test time.