Skip to content

Commit

Permalink
Merge pull request #44 from buwanyouxi/master
Browse files Browse the repository at this point in the history
Translated some Chinese notes into English
  • Loading branch information
FerdinandSu authored Nov 4, 2024
2 parents c08933d + 35ad220 commit e1e5d59
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
43 changes: 26 additions & 17 deletions src/test/java/ReFreSH/JMobileSuit/Demo/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,36 @@ public class ClientTest {

@Before
public void setUp() {
// Initialize the Client and mock IOServer
client = new Client();
mockIoServer = Mockito.mock(IOServer.class);
client.setIO(mockIoServer);
}

@Test
public void testHello() {
// Test the Hello method
client.Hello();
Mockito.verify(mockIoServer).WriteLine("Hello! MobileSuit!");
}

@Test(expected = Exception.class)
public void testByeThrowsException() throws Exception {
client.exp(); // 直接调用会抛出异常
// Directly calling exp() will throw an exception
client.exp();
}


@Test
public void testBye() {
// Test the Bye method with a name parameter
String result = client.Bye("John");
assertEquals("bye", result);
Mockito.verify(mockIoServer).WriteLine("Bye!John");
}

@Test
public void testGoodMorning() {
// Test the GoodMorning method with a parameter
GoodMorningParameter param = new GoodMorningParameter();
param.name = "Alice";
client.GoodMorning(param);
Expand All @@ -50,6 +54,7 @@ public void testGoodMorning() {

@Test
public void testGoodMorning2() {
// Test the GoodMorning2 method with two name parameters
GoodMorningParameter param = new GoodMorningParameter();
param.name = "Alice";
client.GoodMorning2("Bob", param);
Expand All @@ -58,31 +63,32 @@ public void testGoodMorning2() {

@Test
public void testGoodMorningParameterParseFailure() {
// Test parsing failure for the GoodMorningParameter
GoodMorningParameter param = new GoodMorningParameter();
String[] options = {"Alice", "Bob"}; // 超过一个参数
String[] options = {"Alice", "Bob"}; // More than one parameter
assertFalse(param.parse(options));
assertEquals(param.name, "foo"); // 默认值未更改
assertEquals(param.name, "foo"); // Default value should remain unchanged
}


@Test
public void testGoodEvening() {
// Test the GoodEvening method with arguments
String[] args = {"Alice", "Bob"};
client.GoodEvening(args);
Mockito.verify(mockIoServer).WriteLine("Good Evening, Alice");
}


@Test
public void testGoodEveningNoArgs() {
String[] args = {}; // 没有参数
// Test the GoodEvening method with no arguments
String[] args = {}; // No parameters
client.GoodEvening(args);
Mockito.verify(mockIoServer).WriteLine("Good Evening, "); // 确保输出
Mockito.verify(mockIoServer).WriteLine("Good Evening, "); // Ensure output
}


@Test
public void testShowNumber() {
// Test showing a number and an array of numbers
int i = 5;
int[] j = {10};
client.ShowNumber(i, j);
Expand All @@ -92,13 +98,15 @@ public void testShowNumber() {

@Test
public void testGoodEvening2() {
// Test the GoodEvening2 method with two name parameters
String[] args = {"Alice"};
client.GoodEvening2("Bob", args);
Mockito.verify(mockIoServer).WriteLine("Good Evening, Bob and Alice");
}

@Test
public void testSleep() {
// Test the Sleep method with sleeping argument
SleepArgument argument = new SleepArgument();
argument.Name.add("Alice");
argument.SleepTime = 5;
Expand All @@ -111,6 +119,7 @@ public void testSleep() {
// Additional tests for other methods can be added here...
@Test
public void testSleep2() {
// Test the Sleep method with a non-sleeping argument
SleepArgument argument = new SleepArgument();
argument.Name.add("Bob");
argument.isSleeping = false;
Expand All @@ -121,23 +130,25 @@ public void testSleep2() {

@Test
public void testSleepNoArgs() {
SleepArgument argument = new SleepArgument(); // 默认构造
// Test the Sleep method with default arguments
SleepArgument argument = new SleepArgument(); // Default constructor
client.Sleep(argument);
Mockito.verify(mockIoServer).WriteLine(argument.Name.get(0) + " is not sleeping."); // 确保输出
Mockito.verify(mockIoServer).WriteLine(argument.Name.get(0) + " is not sleeping."); // Ensure output
}

@Test
public void testShowNumberEmptyArray() {
// Test showing a number with an empty array
int i = 5;
int[] j = {}; // 空数组
int[] j = {}; // Empty array
client.ShowNumber(i, j);
Mockito.verify(mockIoServer).WriteLine("5");
Mockito.verify(mockIoServer).WriteLine(""); // 输出空行
Mockito.verify(mockIoServer).WriteLine(""); // Output empty line
}


@Test
public void testParse() {
// Test parsing of GoodMorningParameter with various options
GoodMorningParameter param = new GoodMorningParameter();
String[] options = {"Alice"};
assertTrue(param.parse(options));
Expand All @@ -146,8 +157,6 @@ public void testParse() {
String[] options3 = {"Alice", "Bob"};
assertTrue(param.parse(options2));
assertFalse(param.parse(options3));
assertEquals(param.name,"");

assertEquals(param.name, "");
}
}

12 changes: 6 additions & 6 deletions src/test/java/ReFreSH/JMobileSuit/LangResourceBundleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public class LangResourceBundleTest {

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

@Test
public void testStringsAreLoaded() {
// 验证每个字符串属性是否不为 null
// Verify that each string property is not null
assertNotNull(langResourceBundle.Bic);
assertNotNull(langResourceBundle.BicExp1);
assertNotNull(langResourceBundle.BicExp2);
Expand All @@ -35,10 +35,10 @@ public void testStringsAreLoaded() {
assertNotNull(langResourceBundle.ApplicationException);
}

// 可以添加更多的测试方法来验证特定的字符串值
// 例如:
// More test methods can be added to verify specific string values
// For example:
@Test
public void testSpecificStringValue() {
assertEquals("就绪.", langResourceBundle.Done);
assertEquals("就绪.", langResourceBundle.Done); // Check if Done equals "就绪."
}
}
}

0 comments on commit e1e5d59

Please sign in to comment.