Unit testing problems

Asked by Artem OBOTUROV

DHNS Graph module is not public, so it's not possible to use GraphController implementation and following code will fail in test run with NPE:

GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
graphController.getModel(); // NPE - since no implementation is provided.

Any ideas?

Thanks in advance,
Artem

PS: Also, just to mention there are very few tests provided with different modules.

Question information

Language:
English Edit question
Status:
Expired
For:
Gephi Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Mathieu Bastian (mathieu.bastian) said :
#1

Graph models are binded to workspaces and the GraphController.getModel() method will only give you one if a workspace is currently available.

To fix that, do
ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
projectController.newProject();

at the beginning of your unit test code.

See also
http://wiki.gephi.org/index.php/NetBeans_Tips#How_to_use_other_modules_in_Unit_Test

And yes I agree we need more unit tests, especially in Modules we consider stable

Revision history for this message
Artem OBOTUROV (oboturov) said :
#2

If I don't make a dependency on AttributesImpl and DHNS it will always give me NPE, because Lookup can't resolve @ServiceProvider's (they are implemented in AttributesImpl and DHNS respectively for AttributeController and GraphController).

Test is below:
================================= SimpleTest.java ===========================
import org.gephi.data.attributes.api.AttributeController;
import org.gephi.data.attributes.api.AttributeModel;
import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.project.api.ProjectController;
import org.junit.Test;
import org.openide.util.Lookup;

/**
 * @author Artem OBOTUROV
 */
public class SimpleTest {

    @Test
    public void testEvaluateQvalue() throws Exception {
        ProjectController projectController = Lookup.getDefault().lookup(ProjectController.class);
        projectController.newProject();
        AttributeController attributeController = Lookup.getDefault().lookup(AttributeController.class);
        AttributeModel attributeModel = attributeController.getModel();
        GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
        GraphModel graphModel = graphController.getModel();
    }

}
======================================================================

And if add AttributesImpl as a dependency for my module I will have build error because it will generate an empty jar for org-gephi-attibutes.jar

Regards,
Artem

Revision history for this message
Launchpad Janitor (janitor) said :
#3

This question was expired because it remained in the 'Open' state without activity for the last 15 days.