InsertVertexOnEdgeBehaviour behaviour = new InsertVertexOnEdgeBehaviour();
handler.setCurrentState(EditState.MODIFYING);
// current shape is not set
MapMouseEvent event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE,
MapMouseEvent.NONE, MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.RELEASED));
handler.setCurrentShape(shell);
// should work
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertTrue(behaviour.isValid(handler, event, EventType.RELEASED));
// creating not valid state
handler.setCurrentState(EditState.CREATING);
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.RELEASED));
// MOVING not valid state
handler.setCurrentState(EditState.MOVING);
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.RELEASED));
// BUSY not valid state
handler.setCurrentState(EditState.BUSY);
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.RELEASED));
// ILLEGAL not valid state
handler.setCurrentState(EditState.ILLEGAL);
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.RELEASED));
// make sure state is good
handler.setCurrentState(EditState.MODIFYING);
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertTrue(behaviour.isValid(handler, event, EventType.RELEASED));
// Button2 not acceptable
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON2);
assertFalse(behaviour.isValid(handler, event, EventType.RELEASED));
// buttons down not acceptable
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.BUTTON2,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.RELEASED));
// modifiers not acceptable
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.ALT_DOWN_MASK, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.RELEASED));
// DRAGGED not acceptable
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.DRAGGED));
// DOUBLE_CLICK not acceptable
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.DOUBLE_CLICK));
// ENTERED not acceptable
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.ENTERED));
// EXITED not acceptable
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.EXITED));
// MOVED not acceptable
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.MOVED));
// WHEEL not acceptable
event = new MapMouseEvent(null, 10, 10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.WHEEL));
// close enough to edge
event = new MapMouseEvent(null, 10, 8, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertTrue(behaviour.isValid(handler, event, EventType.RELEASED));
// not close enough to edge
event = new MapMouseEvent(null, 0, -10, MapMouseEvent.NONE, MapMouseEvent.NONE,
MapMouseEvent.BUTTON1);
assertFalse(behaviour.isValid(handler, event, EventType.RELEASED));
}