Skip to content

Commit

Permalink
Merge pull request #35 from Sakana152/master
Browse files Browse the repository at this point in the history
PR
  • Loading branch information
FerdinandSu authored Nov 1, 2024
2 parents 45796ae + de8dd37 commit c08933d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/main/java/ReFreSH/JMobileSuit/IO/IOServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class IOServer {
private final Logger logger;
private final StringBuilder PrefixBuilder = new StringBuilder();
private final Stack<Integer> PrefixLengthStack = new Stack<>();
private String content;
public String getContent(){
return content;
}
/**
* Color settings for this IOServer. (default getInstance)
*/
Expand Down Expand Up @@ -481,6 +485,7 @@ public void Write(String content, OutputType type, ConsoleColor customColor) {
private void WriteBase(String content, OutputType type, ConsoleColor customColor) {
if (!IsOutputRedirected()) {
ConsoleColor color = SelectColor(type, customColor);
this.content=content+color.toString();
Output.print(color + content + ClearEffect);
} else {
if (type != OutputType.Prompt)
Expand Down Expand Up @@ -522,7 +527,7 @@ public void WriteLine(String content) {
* @param type Type of this content,this decides how will it be like(color in Console, label in file).
*/
public void WriteLine(String content, OutputType type) {
WriteLineBase(content, type, null);
WriteLineBase(content, type, ConsoleColor.Black);
}

/**
Expand All @@ -539,13 +544,15 @@ public void WriteLine(String content, OutputType type, ConsoleColor customColor)
private void WriteLineBase(String content, OutputType type, ConsoleColor customColor) {
if (!IsOutputRedirected()) {
ConsoleColor color = SelectColor(type, customColor);
this.content=content;
Output.println(color + Prefix() + content + ClearEffect);

} else {
String sb = "[" + LocalDateTime.now() +
"]" +
GetLabel(type) +
content;
this.content=content;
Output.println(sb);
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/test/java/ReFreSH/JMobileSuit/IO/IOServerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@

public class IOServerTests {

private IOServer ioServer;

private IOServer ioServer = new IOServer();
private Logger logger;
private ByteArrayOutputStream outputStream;
private ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
private ByteArrayOutputStream errorStream;
private InputStream inputStream;




@BeforeEach
public void setUp() {
// Mock the logger
Expand All @@ -45,11 +49,10 @@ public void setUp() {
ioServer.Error = new PrintStream(errorStream);
ioServer.SetInput(inputStream);
}

@Test
public void testWriteLine() {
ioServer.WriteLine("Hello World");
assertEquals("Hello World\n", outputStream.toString());
assertEquals("Hello World", ioServer.getContent());
}

@Test
Expand All @@ -69,7 +72,7 @@ public void testWriteException2() {
public void testWriteWithColor() {
ioServer.Write("Colored Text", ConsoleColor.Red);
// Assuming ConsoleColor.Red changes the output, we verify the text without the color code
assertTrue(outputStream.toString().contains("Colored Text"));
assertEquals("Colored Text\u001B[;31m", ioServer.getContent());
}

@Test
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/ReFreSH/JMobileSuit/LangResourceBundleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ReFreSH.JMobileSuit;

import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;

public class LangResourceBundleTest {

private LangResourceBundle langResourceBundle;

@Before
public void setUp() {
// 初始化 LangResourceBundle 实例
langResourceBundle = new LangResourceBundle();
}

@Test
public void testStringsAreLoaded() {
// 验证每个字符串属性是否不为 null
assertNotNull(langResourceBundle.Bic);
assertNotNull(langResourceBundle.BicExp1);
assertNotNull(langResourceBundle.BicExp2);
assertNotNull(langResourceBundle.Done);
assertNotNull(langResourceBundle.Error);
assertNotNull(langResourceBundle.InvalidCommand);
assertNotNull(langResourceBundle.MemberNotFound);
assertNotNull(langResourceBundle.Members);
assertNotNull(langResourceBundle.ObjectNotFound);
assertNotNull(langResourceBundle.Unknown);
assertNotNull(langResourceBundle.ViewBic);
assertNotNull(langResourceBundle.WorkInstance);
assertNotNull(langResourceBundle.ReturnValue);
assertNotNull(langResourceBundle.Default);
assertNotNull(langResourceBundle.AllOK);
assertNotNull(langResourceBundle.ApplicationException);
}

// 可以添加更多的测试方法来验证特定的字符串值
// 例如:
@Test
public void testSpecificStringValue() {
assertEquals("就绪.", langResourceBundle.Done);
}
}

0 comments on commit c08933d

Please sign in to comment.