phamow / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

Abstract ContainerFixture to an interface #281

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

Beginning with motivation... I needed to perform an extra action around 
each call to a fixture container, such as table(), panel() etc. It could 
be logging or waiting for N milliseconds; in my case it was waiting for a 
very short time and trying to obtain the fixture in a loop - basically 
waiting for the screen to populate. Let's stick to the simple waiting for 
N millis example.

I could code it like this:

class ContainerFixtureWrapper {
    ContainerFixture fixture;

    public JTableFixture table(long time) {
        wait(time);
        return fixture.table();
    }

    public JTableFixture table(String name, long time) {
        wait(time);
        return fixture.table(name);
    }

    public JTableFixture table(GenericTypeMatcher matcher, long time) {
        wait(time);
        return fixture.table(matcher);
    }

    public JPanelFixture panel(long time) {
        wait(time);
        return fixture.panel();
    }

    private void wait(long time) {
        // ...
    }

    // ...
}

I can do it, but it produces quite a lot of code, while the only thing I 
need is: "Do this before calling ContainerFixture, and that after the 
call; for every call". In the end we used reflection and copied some code 
from the library, but that's not as clean as it could be.

What I'm requesting is a trivial enhancement: create an interface that 
contains declarations of all these "get a fixture" methods, and make 
ContainerFixture implement it.

Something like:

public interface Container {
    public JTableFixture table();
    public JTableFixture table(String name);
    public JTableFixture table(GenericTypeMatcher matcher);
    public JPanelFixture panel();
    // ...
}

public abstract class ContainerFixture implements Container {
    // ...
}

Having that, I could use Java dynamic proxy API to wrap the calls, writing 
only as much code as I need and keeping it all very simple.

Original issue reported on code.google.com by konrad.g...@gmail.com on 13 Jan 2009 at 10:22

GoogleCodeExporter commented 9 years ago

Original comment by Alex.Rui...@gmail.com on 13 Jan 2009 at 12:50

GoogleCodeExporter commented 9 years ago
Changes in r2204 ( http://code.google.com/p/fest/source/detail?r=2204 )

Thanks,
-Alex

Original comment by Alex.Rui...@gmail.com on 13 Jan 2009 at 1:04