views:

29

answers:

0

I have following class hierarchy

interface IBaseModel
interface IChildModel_A extends IBaseModel
interface IChildModel_B extends IBaseModel

class BaseModel implements IBaseModel
class ChildModel_A extends BaseModel implements IChildModel_A
class ChildModel_B extends BaseModel implements IChildModel_B

I am trying to write unit tests for all these and want to create a separate mock class for each one

class MockBaseModel implements IBaseModel
class MockChildModel_A extends ChildModel_A
class MockChildModel_B extends ChildModel_B

In this setup, what would be a best way to maintain BaseModel's functionality in MockBaseModel and have both MockChildModel_A and MockChildModel_B uses that implementation?

I was thinking I could just have a variable base:MockBaseModel and have MockChildModels route function calls in IBaseModel to the variable

interface IBaseModel {
    function foo():void;
}

class MockChildModel_A {
    private var base:MockBaseModel;

    override public function foo():void {
        base.foo();
    }
}

But this does not work since events dispatched by MockBaseModel doesn't "bubble" up to MockChildModel_A unless I manually re-dispatch all of them. Is there a way for me to accomplish this? or am I just hoping too much?