/*******************************************************************************
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.command.editor.page.name;
import org.eclipse.che.ide.api.command.CommandExecutor;
import org.eclipse.che.ide.api.command.CommandImpl;
import org.eclipse.che.ide.command.editor.EditorMessages;
import org.eclipse.che.ide.command.editor.page.CommandEditorPage.DirtyStateListener;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/** Tests for {@link NamePage}. */
@RunWith(MockitoJUnitRunner.class)
public class NamePageTest {
private static final String COMMAND_NAME = "build";
@Mock
private NamePageView view;
@Mock
private EditorMessages messages;
@Mock
private CommandExecutor commandExecutor;
@InjectMocks
private NamePage page;
@Mock
private DirtyStateListener dirtyStateListener;
@Mock
private CommandImpl editedCommand;
@Before
public void setUp() throws Exception {
when(editedCommand.getName()).thenReturn(COMMAND_NAME);
page.setDirtyStateListener(dirtyStateListener);
page.edit(editedCommand);
}
@Test
public void shouldSetViewDelegate() throws Exception {
verify(view).setDelegate(page);
}
@Test
public void shouldInitializeView() throws Exception {
verify(view).setCommandName(eq(COMMAND_NAME));
}
@Test
public void shouldReturnView() throws Exception {
assertEquals(view, page.getView());
}
@Test
public void shouldNotifyListenerWhenNameChanged() throws Exception {
page.onNameChanged("mvn");
verify(dirtyStateListener, times(2)).onDirtyStateChanged();
}
@Test
public void shouldExecuteCommandWhenTestingRequested() throws Exception {
page.onCommandRun();
verify(commandExecutor).executeCommand(editedCommand);
}
}