/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2015 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the Apache
 * License, Version 2.0. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.sld.editor.expert.gwt.client;

import com.google.gwtmockito.GwtMockitoTestRunner;
import com.google.web.bindery.event.shared.EventBus;
import org.geomajas.sld.editor.expert.common.client.SldEditor;
import org.geomajas.sld.editor.expert.common.client.SldEditorWidgetPresenter;
import org.geomajas.sld.editor.expert.common.client.SldEditorWidgetPresenterImpl;
import org.geomajas.sld.editor.expert.common.client.SldEditorWidgetView;
import org.geomajas.sld.editor.expert.common.client.model.SldGwtServiceAsync;
import org.geomajas.sld.editor.expert.common.client.model.SldManager;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * Sld Editor Widget Presenter Unit Test class.
 *
 * @author David Debuck
 *
 */
@RunWith(GwtMockitoTestRunner.class)
public class SldEditorWidgetPresenterImplTest {

	@Mock
	private SldEditorWidgetView view;

	@Mock
	private SldGwtServiceAsync sldGwtServiceAsync;

	@Mock
	private SldEditor sldEditor;

	@Mock
	private EventBus eventBus;

	@Mock
	private SldManager sldManager;

	private SldEditorWidgetPresenter presenter;

	@Before
	public void PrepareTest() {

		SldEditor.setInstance(sldEditor);
		when(sldEditor.getSldManager()).thenReturn(sldManager);
		when(sldManager.getEventBus()).thenReturn(eventBus);

		presenter = new SldEditorWidgetPresenterImpl(view);

	}

	@Test
	public void onCancelButtonTest() {

		presenter.onCancelButton();
		verify(view).showMessage("sldCancelMessage");

	}

	@Test
	public void onSaveButtonTest() {

		presenter.onSaveButton();
		verify(view).showMessage("sldSaveMessage");

	}

}
@@ -469,30 +469,27 @@
 ort 
-com.google.gwt
+static org.
 mockito.
 GwtM
@@ -488,82 +488,103 @@
 ito.
-Gwt
 Mockito
-TestRunner;%0Aimport com.google.web.bindery.event.shared.EventBus;
+.verify;%0Aimport static org.mockito.Mockito.when;%0Aimport static org.mockito.Mockito.any;%0A
 %0Aimp
@@ -876,16 +876,157 @@
 etView;%0A
+import org.geomajas.sld.editor.expert.common.client.domain.RawSld;%0Aimport org.geomajas.sld.editor.expert.common.client.event.SldCancelEvent;%0A
 import o
@@ -1269,22 +1269,24 @@
 ito.
-Mock;%0A
+Answers;
 %0Aimport 
 stat
@@ -1273,39 +1273,32 @@
 Answers;%0Aimport 
-static 
 org.mockito.Mock
@@ -1301,46 +1301,40 @@
 Mock
-ito.verify;%0Aimport static org.
+;%0A%0Aimport com.google.gwt
 mockito.
 Mock
@@ -1329,28 +1329,89 @@
 mockito.
+Gwt
 Mockito
-.when
+TestRunner;%0Aimport com.google.web.bindery.event.shared.EventBus
 ;%0A%0A/**%0A 
@@ -1748,32 +1748,67 @@
 ventBus;%0A%0A%09@Mock
+(answer=Answers.RETURNS_DEEP_STUBS)
 %0A%09private SldMan
@@ -2206,44 +2206,53 @@
 ify(
-view).showMessage(%22sldCancelMessage%22
+eventBus).fireEvent(any(SldCancelEvent.class)
 );%0A%0A
@@ -2300,80 +2300,186 @@
 ) %7B%0A
-%0A%09%09presenter.onSaveButton();%0A%09%09verify(view).showMessage(%22sldSaveMessage%22
+%09%09%0A%09%09when(view.getSldData()).thenReturn(%22%3Ca/%3E%22);%0A%09%09presenter.onSaveButton();%0A%09%09verify(sldManager.getModel().getRawSld()).setXml(%22%3Ca/%3E%22);%0A%09%09verify(sldManager).validateCurrent(true
 );%0A%0A

test fix