Skip to content

Commit

Permalink
Make test for EditorSaveEvent.bean field
Browse files Browse the repository at this point in the history
* Fixes #8810, #8658
  • Loading branch information
Ilia Motornyi committed Mar 14, 2017
1 parent e786963 commit 156da8b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Expand Up @@ -265,9 +265,10 @@ public void cancel() {
}

private void doCancel(boolean afterBeingSaved) {
T editedBean = edited;
doClose();
if (!afterBeingSaved) {
eventRouter.fireEvent(new EditorCancelEvent<>(this, edited));
eventRouter.fireEvent(new EditorCancelEvent<>(this, editedBean));
}
}

Expand Down
Expand Up @@ -18,6 +18,7 @@
import java.util.Optional;
import java.util.stream.Stream;

import com.vaadin.ui.Grid;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -43,6 +44,11 @@ public class EditorImplTest {
public static class TestEditorImpl extends EditorImpl<Object> implements
EditorSaveListener<Object>, EditorCancelListener<Object> {

@Override
public void doEdit(Object bean) {
super.doEdit(bean);
}

public TestEditorImpl() {
super(new PropertySet<Object>() {
@Override
Expand All @@ -56,6 +62,12 @@ public TestEditorImpl() {
return null;
}
});

}

@Override
public Grid<Object> getParent() {
return new Grid<>();
}

EditorCancelEvent<Object> cancelEvent;
Expand All @@ -64,11 +76,6 @@ public TestEditorImpl() {

EditorServerRpc rpc;

@Override
public boolean isOpen() {
return true;
}

@Override
public boolean isBuffered() {
return true;
Expand Down Expand Up @@ -99,6 +106,8 @@ protected <T extends ServerRpc> void registerRpc(T implementation) {
}
}

private Object beanToEdit = new Object();

private TestEditorImpl editor;
private Binder<Object> binder;

Expand All @@ -109,6 +118,8 @@ public void setUp() {
editor.addCancelListener(editor);
binder = Mockito.mock(Binder.class);
editor.setBinder(binder);
editor.setEnabled(true);
editor.doEdit(beanToEdit);
}

@Test
Expand All @@ -121,6 +132,7 @@ public void save_eventIsFired() {
Assert.assertNull(editor.cancelEvent);

Assert.assertEquals(editor, editor.saveEvent.getSource());
Assert.assertEquals(beanToEdit, editor.saveEvent.getBean());
}

@Test
Expand All @@ -131,6 +143,8 @@ public void cancel_eventIsFired() {
Assert.assertNotNull(editor.cancelEvent);

Assert.assertEquals(editor, editor.cancelEvent.getSource());

Assert.assertEquals(beanToEdit, editor.cancelEvent.getBean());
}

@Test
Expand All @@ -143,6 +157,8 @@ public void saveFromClient_eventIsFired() {
Assert.assertNull(editor.cancelEvent);

Assert.assertEquals(editor, editor.saveEvent.getSource());

Assert.assertEquals(beanToEdit, editor.saveEvent.getBean());
}

@Test
Expand All @@ -153,6 +169,8 @@ public void cancelFromClient_eventIsFired() {
Assert.assertNotNull(editor.cancelEvent);

Assert.assertEquals(editor, editor.cancelEvent.getSource());

Assert.assertEquals(beanToEdit, editor.cancelEvent.getBean());
}

@Test
Expand Down

0 comments on commit 156da8b

Please sign in to comment.