APIReview137191

Summary of the change

Addition of a new class SingleMethod that would hold identification of a file and a method inside it, plus two String constants representing commands for execution and debugging of a single method.

The class SingleMethod would be added to package org.netbeans.spi.project and its content is:

    public static final class SingleMethod {
        private FileObject file;
        private String methodName;
        public SingleMethod(FileObject file, String methodName) {
            this.file = file;
            this.methodName = methodName;
        }
        public FileObject getFile() { return file; }
        public String getMethodName() { return methodName; }
        public static final String COMMAND_RUN_SINGLE_METHOD = "run.single.method";
        public static final String COMMAND_DEBUG_SINGLE_METHOD = "debug.single.method";
        public boolean equals(Object obj) { /*...*/ }
        public int hashCode() { /*...*/ }
    }

(comments and checks of values are stripped)

Goal of the API change

The goal of these changes is to provide an API that would allow implementation of actions "run single test method" and "debug single test method", as requested in issue 72080 ("Would be nice to have a way to run one testXXX method").

Use of the new API

The new API would be used by the code that binds UI for execution of test method with the project back-end that actually performs the execution:

  • in the code on the UI side:
    ActionProvider prjActionProvider = ...

    FileObject testClassFile = ...
    String testMethodName = ...

    SingleMethod methodSpec = new SingleMethod(testClassFile, testMethodName);
    Lookup nodeContext = Lookups.singleton(methodSpec);

    prjActionProvider.invokeAction(SingleMethod.COMMAND_RUN_SINGLE_METHOD, nodeContext);
  • in the code on the side of ActionProvider implementation:
    public void invokeAction(String command, Lookup context) {
        ...
        if (COMMAND_RUN_SINGLE_METHOD.equals(command)) {
            SingleMethod methodSpec = context.lookup(SingleMethod.class);
            if (methodSpec != null) {
                runSingleTestMethod(methodSpec);
            }
        }
        ...
    }
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo