Skip to content

Commit 788f843

Browse files
committed
Update HanaConnectionManagerUnitTest.java
1 parent 4928724 commit 788f843

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/test/java/HanaConnectionManagerUnitTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,36 @@ public void testIsConnected_exception() throws Exception {
7575
injectConnection(manager, throwingConnection);
7676
Assert.assertFalse(manager.isConnected());
7777
}
78+
79+
/**
80+
* Regression test: disconnect() must call close() on the underlying connection
81+
* and leave isConnected() returning false.
82+
*/
83+
@Test
84+
public void testDisconnect_closesConnection() throws Exception {
85+
HanaConnectionManager manager = newManager();
86+
boolean[] closed = {false};
87+
Connection conn = (Connection) Proxy.newProxyInstance(
88+
ClassLoader.getSystemClassLoader(),
89+
new Class[]{Connection.class},
90+
(proxy, method, args) -> {
91+
switch (method.getName()) {
92+
case "close": closed[0] = true; return null;
93+
case "isValid": return true;
94+
default: return null;
95+
}
96+
}
97+
);
98+
injectConnection(manager, conn);
99+
manager.disconnect();
100+
Assert.assertTrue("close() should have been called on the connection", closed[0]);
101+
Assert.assertFalse("isConnected() should be false after disconnect", manager.isConnected());
102+
}
103+
104+
@Test
105+
public void testDisconnect_nullSafe() throws Exception {
106+
HanaConnectionManager manager = newManager(); // connection == null
107+
manager.disconnect(); // must not throw
108+
Assert.assertFalse(manager.isConnected());
109+
}
78110
}

0 commit comments

Comments
 (0)