summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-03-09 01:21:40 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2019-03-11 10:28:42 +0100
commitd44225d85cd8be171c5612f9001a2e455c7d21be (patch)
tree93eab2e0abef31b9557ea04525737837ae25819d
parent391c7a25fa8d247f9f6087f9f19ee330540ad602 (diff)
downloadjgit-d44225d85cd8be171c5612f9001a2e455c7d21be.tar.gz
jgit-d44225d85cd8be171c5612f9001a2e455c7d21be.zip
Use SystemReader in JSchConfigSessionFactoryTest
This isolates the test from the concrete system it's running on. SshSessionFactory reads the user also through SystemReader. Change-Id: I1c796aa1c498fe3967456d8589e6be0a82ab8f44 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/JschConfigSessionFactoryTest.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/JschConfigSessionFactoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/JschConfigSessionFactoryTest.java
index 1e65a20d7f..3de4210baa 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/JschConfigSessionFactoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/JschConfigSessionFactoryTest.java
@@ -49,8 +49,11 @@ import java.nio.file.Files;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
+import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.util.FS;
+import org.eclipse.jgit.util.SystemReader;
import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import com.jcraft.jsch.Session;
@@ -67,8 +70,14 @@ public class JschConfigSessionFactoryTest {
DefaultSshSessionFactory factory = new DefaultSshSessionFactory();
+ @Before
+ public void setup() {
+ SystemReader.setInstance(new MockSystemReader());
+ }
+
@After
public void removeTmpConfig() {
+ SystemReader.setInstance(null);
if (tmpConfigFile == null) {
return;
}
@@ -87,7 +96,8 @@ public class JschConfigSessionFactoryTest {
Session session = createSession("ssh://egit/egit/egit");
assertEquals("egit", session.getHost());
// No user in URI, none in ssh config: default is OS user name
- assertEquals(System.getProperty("user.name"), session.getUserName());
+ assertEquals(SystemReader.getInstance().getProperty("user.name"),
+ session.getUserName());
assertEquals(22, session.getPort());
}