@Test public void shouldExtractObjectWhenJsonIsValid() throws Exception { DropEvent dropEvent = Mockito.mock(DropEvent.class); String json = "some json"; when(dropEvent.getData("json")).thenReturn(json); when(overlayTypesParser.isValidJSON(json)).thenReturn(true); NativeDragDataObject nativeDragData = Mockito.mock(NativeDragDataObject.class); when(overlayTypesParser.get(json)).thenReturn(nativeDragData); Optional<DragDataObject> extracted = dataObjectFromEventExtractor.extractDroppedObjectFromEvent(dropEvent); verify(dropEvent).stopPropagation(); verify(dropEvent).preventDefault(); assertThat(extracted.get()).isEqualTo(nativeDragData); }
@Test public void shouldReturnAbsentWhenJsonIsNotValid() throws Exception { DropEvent dropEvent = Mockito.mock(DropEvent.class); String json = "some json"; when(dropEvent.getData("json")).thenReturn(json); when(overlayTypesParser.isValidJSON(json)).thenReturn(false); NativeDragDataObject nativeDragData = Mockito.mock(NativeDragDataObject.class); when(overlayTypesParser.get(json)).thenReturn(nativeDragData); Optional<DragDataObject> extracted = dataObjectFromEventExtractor.extractDroppedObjectFromEvent(dropEvent); verify(dropEvent).stopPropagation(); verify(dropEvent).preventDefault(); assertThat(extracted.isPresent()).isEqualTo(false); }
@Test public void shouldExtractDataFromEventAndInformSourcelistManager() throws Exception { DropEvent event = Mockito.mock(DropEvent.class); DragDataObject dragDataObject = Mockito.mock(DragDataObject.class); Optional<DragDataObject> optionalDragData = Optional.fromNullable(dragDataObject); when(dragDataObjectFromEventExtractor.extractDroppedObjectFromEvent(event)).thenReturn(optionalDragData); String itemId = "itemId"; when(dragDataObject.getItemId()).thenReturn(itemId); String sourceId = "sourceId"; when(dragDataObject.getSourceId()).thenReturn(sourceId); dropHandler.onDrop(event); verify(sourceListManagerAdapter).dragEnd(itemId, sourceId); }
public Optional<DragDataObject> extractDroppedObjectFromEvent(DropEvent dropEvent) { String jsonObject = dropEvent.getData("json"); Optional<DragDataObject> dragData; if (overlayTypesParser.isValidJSON(jsonObject)) { NativeDragDataObject nativeDragData = overlayTypesParser.get(jsonObject); DragDataObject dragDataObject = nativeDragData; dragData = Optional.fromNullable(dragDataObject); } else { dragData = Optional.absent(); } dropEvent.stopPropagation(); dropEvent.preventDefault(); return dragData; }
@Override public void onDrop(DropEvent event) { Optional<DragDataObject> objectFromEvent = dragDataObjectFromEventExtractor.extractDroppedObjectFromEvent(event); if (objectFromEvent.isPresent()) { informSourceListManagerAboutDrop(objectFromEvent.get()); } }
@Override public void onDrop(DropEvent event) { Optional<DragDataObject> objectFromEvent = objectFromEventExtractor.extractDroppedObjectFromEvent(event); if (objectFromEvent.isPresent()) { DragDataObject dataObject = objectFromEvent.get(); sourceListPresenter.onDropEvent(dataObject.getItemId(), dataObject.getSourceId()); } }
public void addDomHandlerOnObjectDrop(final GapDropHandler dragGapDropHandler) { droppable.addDropHandler(new DropHandler() { @Override public void onDrop(DropEvent event) { Optional<DragDataObject> objectFromEvent = dataObjectFromEventExtractor.extractDroppedObjectFromEvent(event); if (objectFromEvent.isPresent()) { dragGapDropHandler.onDrop(objectFromEvent.get()); } } }); }
@Test public void shouldHandleDropAsOnBlur() { // given DropEvent event = mock(DropEvent.class); // when testObj.bind(droppableObject, presenterHandler); testObj.onDrop(event); // then verify(presenterHandler).onBlur(Matchers.any(BlurEvent.class)); }
@Override public void onDrop(DropEvent event) { BlurEvent noopBlurEvent = new BlurEvent() { }; callBlurHandler(noopBlurEvent); }
public HandlerRegistration addDropHandler(DropHandler handler) { return addBitlessDomHandler(handler, DropEvent.getType()); }
/** * */ @Override public HandlerRegistration addDropHandler(DropHandler handler) { return addBitlessDomHandler(handler, DropEvent.getType()); }
@Override public com.google.gwt.event.shared.HandlerRegistration addDropHandler(DropHandler handler) { return this.addBitlessDomHandler(handler, DropEvent.getType()); }
@Override public HandlerRegistration addDropHandler(DropHandler handler) { return this.addBitlessDomHandler(handler, DropEvent.getType()); }