Skip to content

Commit b10551a

Browse files
committed
TDD: Write test code for Jsch model classes
1 parent 3d479ee commit b10551a

File tree

3 files changed

+162
-14
lines changed

3 files changed

+162
-14
lines changed

Common/src/main/java/root/common/server/implement/JschConnectionInfo.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,10 @@ public JschConnectionInfo(String serverName, ServerOS serverOS, String host, int
2727
this.alc = new AlertLogCommand();
2828
}
2929

30-
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, String port, String userName,
31-
String password) {
32-
this(serverName, serverOS, host, 22, userName, password);
33-
this.setPort(port);
34-
}
35-
36-
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, int port, String userName,
37-
String password, AlertLogCommand alc) {
38-
this(serverName, serverOS, host, port, userName, password);
39-
this.alc = alc;
40-
}
41-
4230
public JschConnectionInfo(String serverName, ServerOS serverOS, String host, String port, String userName,
4331
String password, AlertLogCommand alc) {
44-
this(serverName, serverOS, host, 22, userName, password, alc);
32+
this(serverName, serverOS, host, 22, userName, password);
33+
this.setAlc(alc);
4534
this.setPort(port);
4635
}
4736

@@ -58,7 +47,11 @@ public void setPort(String portString) {
5847
try {
5948
this.port = Integer.parseInt(portString);
6049
} catch (NumberFormatException e) {
61-
this.port = 22; // �⺻��
50+
this.port = 22;
6251
}
6352
}
53+
54+
public void setPort(int port) {
55+
this.port = port;
56+
}
6457
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package root.common.server.implement;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
import java.util.Arrays;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
public class AlertLogCommandTest {
12+
13+
public static int readLine = 1000;
14+
public static String readFilePath = "/alertLog.txt";
15+
public static String[] catchErrorMsg = new String[] { "1", "2" };
16+
17+
@Test
18+
public void testConstructor1() {
19+
new AlertLogCommand();
20+
}
21+
22+
@Test
23+
public void testConstructor2() {
24+
new AlertLogCommand(readLine, readFilePath);
25+
}
26+
27+
@Test
28+
public void testConstructor3() {
29+
new AlertLogCommand(readLine, readFilePath, catchErrorMsg);
30+
}
31+
32+
@Test
33+
public void testGetterSetter() {
34+
AlertLogCommand alc = new AlertLogCommand();
35+
alc.setReadLine(readLine);
36+
alc.setReadFilePath(readFilePath);
37+
alc.setCatchErrorMsg(catchErrorMsg);
38+
assertEquals(readLine, alc.getReadLine());
39+
assertEquals(readFilePath, alc.getReadFilePath());
40+
assertEquals(catchErrorMsg, alc.getCatchErrorMsg());
41+
}
42+
43+
@Test
44+
public void testToString() {
45+
AlertLogCommand alc = new AlertLogCommand(readLine, readFilePath, catchErrorMsg);
46+
String expected = "AlertLogCommand(readLine=" + alc.getReadLine() + ", readFilePath=" + alc.getReadFilePath()
47+
+ ", catchErrorMsg=" + Arrays.toString(alc.getCatchErrorMsg()) + ")";
48+
assertEquals(expected, alc.toString());
49+
}
50+
51+
@Test
52+
public void testEquals() {
53+
AlertLogCommand alc1 = new AlertLogCommand(readLine, readFilePath, catchErrorMsg);
54+
AlertLogCommand alc2 = new AlertLogCommand(readLine, readFilePath, catchErrorMsg);
55+
56+
assertTrue(alc1.equals(alc1));
57+
assertTrue(alc1.equals(alc2));
58+
assertFalse(alc1.equals(new Object()));
59+
60+
alc1 = null;
61+
assertFalse(alc2.equals(alc1));
62+
assertFalse(alc2.equals(new Object()));
63+
}
64+
65+
@Test
66+
public void testHashCode() {
67+
AlertLogCommand alc = new AlertLogCommand(readLine, readFilePath, catchErrorMsg);
68+
alc.hashCode();
69+
}
70+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package root.common.server.implement;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
public class JschConnectionInfoTest {
11+
12+
public static String serverName = "testServer";
13+
public static ServerOS serverOS = ServerOS.LINUX;
14+
public static String host = "111.111.111.111";
15+
public static int port = 22;
16+
public static String userName = "userName";
17+
public static String password = "password";
18+
public static AlertLogCommand alc = new AlertLogCommand();
19+
20+
@Test
21+
public void testConstructor1() {
22+
JschConnectionInfo jsch = new JschConnectionInfo();
23+
assertNotNull(jsch.getAlc());
24+
}
25+
26+
@Test
27+
public void testConstructor2() {
28+
new JschConnectionInfo(serverName, serverOS, host, "22", userName, password, alc);
29+
}
30+
31+
@Test
32+
public void testConstructor3() {
33+
new JschConnectionInfo(host, "21", userName, password);
34+
}
35+
36+
@Test
37+
public void testGetterSetter() {
38+
JschConnectionInfo jsch = new JschConnectionInfo();
39+
jsch.setServerName(serverName);
40+
jsch.setServerOS(serverOS);
41+
jsch.setHost(host);
42+
jsch.setPort(port);
43+
jsch.setUserName(userName);
44+
jsch.setPassword(password);
45+
jsch.setAlc(alc);
46+
47+
assertEquals(serverName, jsch.getServerName());
48+
assertEquals(serverOS, jsch.getServerOS());
49+
assertEquals(host, jsch.getHost());
50+
assertEquals(port, jsch.getPort());
51+
assertEquals(userName, jsch.getUserName());
52+
assertEquals(password, jsch.getPassword());
53+
assertEquals(alc, jsch.getAlc());
54+
}
55+
56+
@Test
57+
public void testToString() {
58+
JschConnectionInfo jsch = new JschConnectionInfo(serverName, serverOS, host, "22", userName, password, alc);
59+
String expected = "JschConnectionInfo(serverName=" + jsch.getServerName() + ", serverOS=" + jsch.getServerOS()
60+
+ ", host=" + jsch.getHost() + ", port=" + jsch.getPort() + ", userName=" + jsch.getUserName()
61+
+ ", password=" + jsch.getPassword() + ", alc=" + jsch.getAlc() + ")";
62+
63+
assertEquals(expected, jsch.toString());
64+
}
65+
66+
@Test
67+
public void testEquals() {
68+
JschConnectionInfo jsch1 = new JschConnectionInfo(serverName, serverOS, host, "22", userName, password, alc);
69+
JschConnectionInfo jsch2 = new JschConnectionInfo(serverName, serverOS, host, "22", userName, password, alc);
70+
71+
assertTrue(jsch1.equals(jsch2));
72+
assertTrue(jsch1.equals(jsch2));
73+
assertFalse(jsch1.equals(new Object()));
74+
75+
jsch1 = null;
76+
assertFalse(jsch2.equals(jsch1));
77+
assertFalse(jsch2.equals(new Object()));
78+
}
79+
80+
@Test
81+
public void testHashCode() {
82+
JschConnectionInfo jsch = new JschConnectionInfo(serverName, serverOS, host, "22", userName, password, alc);
83+
jsch.hashCode();
84+
}
85+
}

0 commit comments

Comments
 (0)