sarahtattersall / PIPE

PIPE - Platform Independent Petri Net Editor
MIT License
236 stars 73 forks source link

Should program to interface #9

Closed sarahtattersall closed 10 years ago

sarahtattersall commented 11 years ago

As a good rule of thumb, and to make use of mocks in testing PIPE should make use of interfaces where possible.

For example ArrayList x = new ArrayList();

would become List x = new ArrayList();

Method parameters also need to be changed to interfaces allowing them to be mocked. For example in TransitionView.java the method public TransitionView paste(double x, double y, boolean fromAnotherView, PetriNetView model) would be far better if PetriNetView was an interface and therefore mockable.

sarahtattersall commented 11 years ago

It turns out Mockito can mock classes too, but this is still a good practice.

sjdayday commented 11 years ago

Agreed, especially when there are multiple possible implementations of an interface. For a single class, sometimes it's easier to subclass it, and override the method(s) that are making the test difficult. Some examples in the existing unit tests (private classes in the test class)...for discussion sometime...Steve

Steve Doubleday stevedoubleday@gmail.com 818-648-8381 twitter: sjdayday

On Oct 9, 2013, at 10:54 AM, Sarah Tattersall notifications@github.com wrote:

As a good rule of thumb, and to make use of mocks in testing PIPE should make use of interfaces where possible.

For example ArrayList x = new ArrayList();

would become List x = new ArrayList();

Method parameters also need to be changed to interfaces allowing them to be mocked. For example in TransitionView.java the method public TransitionView paste(double x, double y, boolean fromAnotherView, PetriNetView model) would be far better if PetriNetView was an interface and therefore mockable.

— Reply to this email directly or view it on GitHub.

sarahtattersall commented 10 years ago

Closing due to moving Petri Net logic to PIPECore