1

私はこのコードを持っています:

   //FrameFixture frame = (...got it from window, main frame...)
   JTableFixture table = frame.table(new GenericTypeMatcher<JTable>(JTable.class) {
         @Override protected boolean isMatching(JTable table) {
            return (table instanceof myTreeTable); 
         }  
    });

彼の .class (基本コンポーネントから継承) によってコンポーネントを取得するためのより良い種類のシンタックス シュガーはありませんか?

4

1 に答える 1

1

If you need implementation of ComponentMatcher then TypeMatcher can do matching based on type.

However TypeMatcher cannot be used in case of ContainerFixture.table methods as they require GenericTypeMatcher.

TypeMatcher and GenericTypeMatcher both implement ComponentMatcher but aren't in the same hierarchy.

GenericTypeMatcher is abstract, so you have to provide an implementation. You could get away with your own extension if needed, ie:

class ConcreteTypeMatcher<T extends Component> extends GenericTypeMatcher<T> {
    Class<T> type;

    public ConcreteTypeMatcher(Class<T> supportedType) {
        super(supportedType);
        this.type = supportedType;
    }

    @Override
    protected boolean isMatching(T arg) {
        return type.isInstance(arg);
    }
}

And use it like this:

JTableFixture table = frame.table(
      new ConcreteTypeMatcher<myTreeTable>(myTreeTable.class));
于 2012-07-27T05:34:56.903 に答える