-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing @Override-Annotations, add more tests
- Loading branch information
1 parent
573b541
commit b4f027b
Showing
6 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/test/java/de/marza/firstspirit/modules/logging/console/ConsoleOutputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package de.marza.firstspirit.modules.logging.console; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import java.awt.Color; | ||
|
||
import javax.swing.text.Document; | ||
import javax.swing.text.JTextComponent; | ||
import javax.swing.text.SimpleAttributeSet; | ||
import javax.swing.text.StyleConstants; | ||
|
||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ConsoleOutputStreamTest { | ||
|
||
private ConsoleOutputStream testling; | ||
|
||
private SimpleAttributeSet attributes; | ||
|
||
@Mock | ||
private MessageConsole console; | ||
|
||
@Mock | ||
private Document document; | ||
|
||
@Mock | ||
private JTextComponent textComponent; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
testling = new ConsoleOutputStream(console, Color.BLACK, null); | ||
|
||
when(console.getDocument()).thenReturn(document); | ||
when(console.getTextComponent()).thenReturn(textComponent); | ||
|
||
attributes = new SimpleAttributeSet(); | ||
StyleConstants.setForeground(attributes, Color.BLACK); | ||
} | ||
|
||
@Test | ||
public void flushAppend() throws Exception { | ||
when(console.isAppend()).thenReturn(true); | ||
|
||
testling.write("Test 123\n".getBytes()); | ||
|
||
testling.flush(); | ||
|
||
verify(document).insertString(0, "Test 123\n", attributes); | ||
} | ||
|
||
@Test | ||
public void flushInsert() throws Exception { | ||
when(console.isAppend()).thenReturn(false); | ||
|
||
testling.write("Test 123".getBytes()); | ||
|
||
testling.flush(); | ||
|
||
testling.write("\n".getBytes()); | ||
|
||
testling.flush(); | ||
|
||
verify(document).insertString(0, "Test 123\n", attributes); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/de/marza/firstspirit/modules/logging/console/MessageConsoleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package de.marza.firstspirit.modules.logging.console; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import java.awt.Color; | ||
|
||
import javax.swing.text.Document; | ||
import javax.swing.text.JTextComponent; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.sameInstance; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class MessageConsoleTest { | ||
|
||
private MessageConsole testling; | ||
|
||
@Mock | ||
private JTextComponent textComponent; | ||
|
||
@Mock | ||
private Document document; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
|
||
when(textComponent.getDocument()).thenReturn(document); | ||
|
||
testling = new MessageConsole(textComponent); | ||
|
||
verify(textComponent).setEditable(false); | ||
verify(textComponent).setBackground(Color.WHITE); | ||
} | ||
|
||
@Test | ||
public void getDocument() throws Exception { | ||
assertThat(testling.getDocument(), is(sameInstance(document))); | ||
} | ||
|
||
@Test | ||
public void isAppend() throws Exception { | ||
assertThat(testling.isAppend(), is(true)); | ||
} | ||
|
||
@Test | ||
public void getTextComponent() throws Exception { | ||
assertThat(testling.getTextComponent(), is(sameInstance(textComponent))); | ||
} | ||
|
||
} |