|
| 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