Added test. removed implementation of shell
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
d87aabd465
commit
2df99debf8
@ -35,7 +35,8 @@ public final class ConsoleOutputManager implements ConsoleOutputDisplay {
|
|||||||
* @see java.lang.Runnable#run() */
|
* @see java.lang.Runnable#run() */
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!text.getText().isEmpty()) {
|
final String initialText = text.getText();
|
||||||
|
if (initialText != null && !initialText.isEmpty()) {
|
||||||
text.append(System.lineSeparator());
|
text.append(System.lineSeparator());
|
||||||
}
|
}
|
||||||
text.append(next);
|
text.append(next);
|
||||||
|
@ -73,9 +73,8 @@ import java.io.BufferedReader;
|
|||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
|
||||||
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.swt.widgets.Text;
|
||||||
|
|
||||||
import net.bigeon.gclc.utils.PipedConsoleInput;
|
import net.bigeon.gclc.utils.PipedConsoleInput;
|
||||||
@ -85,7 +84,7 @@ import net.bigeon.gclc.utils.PipedConsoleOutput;
|
|||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public final class SWTConsoleShell extends Shell {
|
public final class SWTConsole extends Composite {
|
||||||
|
|
||||||
private ConsoleInputManager inputManager;
|
private ConsoleInputManager inputManager;
|
||||||
private ConsoleOutputManager outputManager;
|
private ConsoleOutputManager outputManager;
|
||||||
@ -93,19 +92,14 @@ public final class SWTConsoleShell extends Shell {
|
|||||||
|
|
||||||
/** Create the shell.
|
/** Create the shell.
|
||||||
*
|
*
|
||||||
* @param display the display
|
* @param parent the containing composite
|
||||||
* @param style the shell style */
|
* @param style the shell style */
|
||||||
public SWTConsoleShell(final Display display, final int style) {
|
public SWTConsole(final Composite parent, final int style) {
|
||||||
super(display, style);
|
super(parent, style);
|
||||||
setLayout(new GridLayout(2, false));
|
setLayout(new GridLayout(2, false));
|
||||||
createContents();
|
createContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkSubclass() {
|
|
||||||
// Disable the check that prevents subclassing of SWT components
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Create contents of the shell. */
|
/** Create contents of the shell. */
|
||||||
private void createContents() {
|
private void createContents() {
|
||||||
final Text output = new Text(this,
|
final Text output = new Text(this,
|
||||||
@ -119,7 +113,6 @@ public final class SWTConsoleShell extends Shell {
|
|||||||
inputManager = new ConsoleInputManager(input);
|
inputManager = new ConsoleInputManager(input);
|
||||||
outputManager = new ConsoleOutputManager(output);
|
outputManager = new ConsoleOutputManager(output);
|
||||||
promptManager = new ConsolePromptManager(prompt);
|
promptManager = new ConsolePromptManager(prompt);
|
||||||
setText("Console Application"); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Connect the console parts to the shell.
|
/** Connect the console parts to the shell.
|
@ -40,11 +40,16 @@ public class ConsoleOutputManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
* {@link net.bigeon.gclc.swt.ConsoleOutputManager#appendConsoleOutput(java.lang.String)}. */
|
* {@link net.bigeon.gclc.swt.ConsoleOutputManager#appendLine(java.lang.String)}. */
|
||||||
@Test
|
@Test
|
||||||
public void testAppendConsoleOutput() {
|
public void testAppendConsoleOutput() {
|
||||||
com.appendConsoleOutput("abc");
|
when(text.getText()).thenReturn("", "abc",
|
||||||
|
"abc" + System.lineSeparator() + "def");
|
||||||
|
com.appendLine("abc");
|
||||||
verify(text).append("abc");
|
verify(text).append("abc");
|
||||||
|
com.appendLine("def");
|
||||||
|
verify(text).append(System.lineSeparator());
|
||||||
|
verify(text).append("def");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -60,7 +65,7 @@ public class ConsoleOutputManagerTest {
|
|||||||
forwardThread.join(500);
|
forwardThread.join(500);
|
||||||
com.setManager(null);
|
com.setManager(null);
|
||||||
forwardThread.join();
|
forwardThread.join();
|
||||||
verify(text).append(System.lineSeparator() + "line");
|
verify(text).append("line");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.doAnswer;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
/** @author Emmanuel Bigeon */
|
||||||
|
public class PromptReadingRunnableTest {
|
||||||
|
private final Label view = mock(Label.class);
|
||||||
|
private final Display display = mock(Display.class);
|
||||||
|
{
|
||||||
|
when(view.getDisplay()).thenReturn(display);
|
||||||
|
doAnswer(new Answer<Object>() {
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see
|
||||||
|
* org.mockito.stubbing.Answer#answer(org.mockito.invocation.InvocationOnMock) */
|
||||||
|
@Override
|
||||||
|
public Object answer(final InvocationOnMock invocation) throws Throwable {
|
||||||
|
final Runnable runnable = invocation.getArgument(0);
|
||||||
|
runnable.run();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}).when(display).syncExec(any(Runnable.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for {@link net.bigeon.gclc.swt.PromptReadingRunnable#run()}.
|
||||||
|
*
|
||||||
|
* @throws IOException if an error occurred */
|
||||||
|
@Test
|
||||||
|
public void testRun() throws IOException {
|
||||||
|
final BufferedReader reader = mock(BufferedReader.class);
|
||||||
|
when(reader.readLine()).thenReturn("abc", "def", null);
|
||||||
|
|
||||||
|
final PromptReadingRunnable runnable = new PromptReadingRunnable(reader, view);
|
||||||
|
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for {@link net.bigeon.gclc.swt.PromptReadingRunnable#run()}.
|
||||||
|
*
|
||||||
|
* @throws IOException if an error occurred */
|
||||||
|
@Test
|
||||||
|
public void testRunWithIO() throws IOException {
|
||||||
|
final BufferedReader reader = mock(BufferedReader.class);
|
||||||
|
when(reader.readLine()).thenThrow(new IOException());
|
||||||
|
|
||||||
|
final PromptReadingRunnable runnable = new PromptReadingRunnable(reader, view);
|
||||||
|
final Logger logger = Logger.getLogger(PromptReadingRunnable.class.getName());
|
||||||
|
final Level back = logger.getLevel();
|
||||||
|
logger.setLevel(Level.OFF);
|
||||||
|
|
||||||
|
runnable.run();
|
||||||
|
logger.setLevel(back);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.widgets.Composite;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/** @author Emmanuel Bigeon */
|
||||||
|
public class SWTConsoleShellTest {
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.swt.SWTConsole#SWTConsole(Composite, int)}. */
|
||||||
|
@Test
|
||||||
|
public void testSWTConsoleShell() {
|
||||||
|
final SWTConsole console = new SWTConsole(new Shell(), SWT.NONE);
|
||||||
|
assertNotNull("View should be initialized with managers",
|
||||||
|
console.getInputManager());
|
||||||
|
assertNotNull("View should be initialized with managers",
|
||||||
|
console.getOutputManager());
|
||||||
|
assertNotNull("View should be initialized with managers",
|
||||||
|
console.getPromptManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.swt.SWTConsole#connect(net.bigeon.gclc.utils.PipedConsoleInput, net.bigeon.gclc.utils.PipedConsoleOutput, java.io.BufferedReader)}. */
|
||||||
|
@Test
|
||||||
|
public void testConnect() {
|
||||||
|
final SWTConsole console = new SWTConsole(new Shell(), SWT.NONE);
|
||||||
|
// Disconnection should work.
|
||||||
|
console.connect(null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package net.bigeon.gclc.swt;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.eclipse.swt.SWT;
|
||||||
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/** @author Emmanuel Bigeon */
|
||||||
|
public class SWTConsoleViewTest {
|
||||||
|
|
||||||
|
/** Test method for {@link net.bigeon.gclc.swt.SWTConsoleView#setFocus()}. */
|
||||||
|
@Test
|
||||||
|
public void testSetFocus() {
|
||||||
|
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
|
||||||
|
assertFalse("Non visible component set focus should fail", view.setFocus());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.swt.SWTConsoleView#SWTConsoleView(org.eclipse.swt.widgets.Composite, int)}. */
|
||||||
|
@Test
|
||||||
|
public void testSWTConsoleView() {
|
||||||
|
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
|
||||||
|
assertNotNull("View should be initialized with managers", view.getInputManager());
|
||||||
|
assertNotNull("View should be initialized with managers",
|
||||||
|
view.getOutputManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link net.bigeon.gclc.swt.SWTConsoleView#setManager(net.bigeon.gclc.utils.PipedConsoleOutput, net.bigeon.gclc.utils.PipedConsoleInput)}. */
|
||||||
|
@Test
|
||||||
|
public void testSetManager() {
|
||||||
|
final SWTConsoleView view = new SWTConsoleView(new Shell(), SWT.NONE);
|
||||||
|
// Disconnection should work.
|
||||||
|
view.setManager(null, null);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user