-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add some Unit test to IOServer #46
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,12 @@ public void testWriteWithColor() { | |
assertEquals("Colored Text\u001B[;31m", ioServer.getContent()); | ||
} | ||
|
||
@Test | ||
public void testWriteDefault() { | ||
ioServer.Write("Default Text"); | ||
assertEquals("Default Text\u001B[;1;m", ioServer.getContent()); | ||
} | ||
|
||
@Test | ||
public void testIsInputRedirected2() { | ||
assertTrue(ioServer.IsInputRedirected()); | ||
|
@@ -292,6 +298,33 @@ public void testReadLineWithoutPrompt() { | |
assertEquals(testInput, result); | ||
} | ||
|
||
@Test | ||
public void testReadLineWithoutInputStream() { | ||
String testInput = ""; | ||
InputStream inputStream = new ByteArrayInputStream(testInput.getBytes()); | ||
IOServer ioserver = getInstance(); | ||
ioserver.SetInput(inputStream); | ||
String prompt = ""; | ||
boolean newLine = true; | ||
String defaultValue ="Default Value"; | ||
String result = ioserver.ReadLine(prompt, defaultValue, newLine); | ||
|
||
assertEquals(defaultValue, result); | ||
} | ||
|
||
@Test | ||
public void testReadLineWithPromptAndNewline() { | ||
String testInput = "Test Input"; | ||
InputStream inputStream = new ByteArrayInputStream(testInput.getBytes()); | ||
IOServer ioserver = getInstance(); | ||
ioserver.SetInput(inputStream); | ||
String prompt = ""; | ||
boolean newLine = true; | ||
String result = ioserver.ReadLine(prompt, newLine); | ||
|
||
assertEquals(testInput, result); | ||
} | ||
|
||
@Test | ||
public void testRead() throws IOException { | ||
String testInput = "Test Input"; | ||
|
@@ -425,6 +458,69 @@ public void testSetPrefix() { | |
assertEquals(1, prefixLengthStack.size()); | ||
assertEquals(Integer.valueOf(10), prefixLengthStack.pop()); | ||
} | ||
@Test | ||
public void testSelectColorWithDefault() { | ||
ColorSetting colorSetting = new ColorSetting(); | ||
|
||
// 测试当 customColor 为 null 时返回默认颜色 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use English for I18n |
||
assertEquals(ConsoleColor.White, ColorSetting.selectColor(OutputType.Default, null, colorSetting)); | ||
assertEquals(ConsoleColor.Magenta, ColorSetting.selectColor(OutputType.Prompt, null, colorSetting)); | ||
assertEquals(ConsoleColor.Red, ColorSetting.selectColor(OutputType.Error, null, colorSetting)); | ||
assertEquals(ConsoleColor.Green, ColorSetting.selectColor(OutputType.AllOk, null, colorSetting)); | ||
assertEquals(ConsoleColor.Yellow, ColorSetting.selectColor(OutputType.ListTitle, null, colorSetting)); | ||
assertEquals(ConsoleColor.DarkCyan, ColorSetting.selectColor(OutputType.CustomInfo, null, colorSetting)); | ||
assertEquals(ConsoleColor.DarkBlue, ColorSetting.selectColor(OutputType.MobileSuitInfo, null, colorSetting)); | ||
} | ||
|
||
|
||
@Test | ||
public void testSelectColorWithCustomColor() { | ||
ColorSetting colorSetting = new ColorSetting(); | ||
|
||
ConsoleColor customColor = ConsoleColor.Blue; // 定义一个自定义颜色 | ||
// 测试当 customColor 非空时返回自定义颜色 | ||
assertEquals(customColor, ColorSetting.selectColor(OutputType.Default, customColor, colorSetting)); | ||
assertEquals(customColor, ColorSetting.selectColor(OutputType.Prompt, customColor, colorSetting)); | ||
assertEquals(customColor, ColorSetting.selectColor(OutputType.Error, customColor, colorSetting)); | ||
assertEquals(customColor, ColorSetting.selectColor(OutputType.AllOk, customColor, colorSetting)); | ||
assertEquals(customColor, ColorSetting.selectColor(OutputType.ListTitle, customColor, colorSetting)); | ||
assertEquals(customColor, ColorSetting.selectColor(OutputType.CustomInfo, customColor, colorSetting)); | ||
assertEquals(customColor, ColorSetting.selectColor(OutputType.MobileSuitInfo, customColor, colorSetting)); | ||
} | ||
|
||
@Test | ||
public void testGetInstance() { | ||
ColorSetting colorSetting1 = ColorSetting.getInstance(); | ||
ColorSetting colorSetting2 = ColorSetting.getInstance(); | ||
|
||
assertNotNull(colorSetting1); | ||
assertNotNull(colorSetting2); | ||
// 检查是否每次都返回新的实例 | ||
assertNotSame(colorSetting1, colorSetting2); | ||
} | ||
@Test | ||
public void testDefaultColorsInitialization() { | ||
ColorSetting colorSetting = new ColorSetting(); | ||
|
||
assertEquals(ConsoleColor.White, colorSetting.DefaultColor); | ||
assertEquals(ConsoleColor.Magenta, colorSetting.PromptColor); | ||
assertEquals(ConsoleColor.Red, colorSetting.ErrorColor); | ||
assertEquals(ConsoleColor.Green, colorSetting.AllOkColor); | ||
assertEquals(ConsoleColor.Yellow, colorSetting.ListTitleColor); | ||
assertEquals(ConsoleColor.DarkCyan, colorSetting.CustomInformationColor); | ||
assertEquals(ConsoleColor.DarkBlue, colorSetting.InformationColor); | ||
} | ||
@Test | ||
public void testColorForDifferentOutputTypes() { | ||
ColorSetting colorSetting = new ColorSetting(); | ||
|
||
assertEquals(ConsoleColor.White, colorSetting.DefaultColor); | ||
assertEquals(ConsoleColor.Magenta, colorSetting.PromptColor); | ||
assertEquals(ConsoleColor.Red, colorSetting.ErrorColor); | ||
assertEquals(ConsoleColor.Green, colorSetting.AllOkColor); | ||
assertEquals(ConsoleColor.Yellow, colorSetting.ListTitleColor); | ||
assertEquals(ConsoleColor.DarkCyan, colorSetting.CustomInformationColor); | ||
assertEquals(ConsoleColor.DarkBlue, colorSetting.InformationColor); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unbelievable to use Jvav 1.6 in 2024. as described in POM.xml, JMobileSuit uses Jvav 21.