Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The exception generated in the <code>sendMessage()</code> class will be available in the test method. Add a try catch block around the <code>sendMessage()</code> method like this</p> <pre><code>@Test public testSendMessageToStub() { try { object.sendMehssage(); } catch(Excpetion e) //Use more specific exception type if you know { fail(e.getMessage()); } } </code></pre> <p>I have tried this in my code. It worked for me. Let me know.</p> <pre><code>public DBConnectionInfo connectionInit() { loadConnectionInfo(); try { Class.forName(dbObject.getDriver()); } catch (Exception e) { Logger lgr = Logger.getLogger(PostgreLocationManager.class.getName()); lgr.log(Level.SEVERE, e.getMessage(), e); } try { dbObject.setConnection(DriverManager.getConnection(dbObject.getDatabaseURL(), dbObject.getUserName(), dbObject.getPassword())); } catch (Exception e) { Logger lgr = Logger.getLogger(PostgreLocationManager.class.getName()); lgr.log(Level.SEVERE, e.getMessage(), e); } return dbObject; } </code></pre> <p>The test case for the above class.</p> <pre><code>@Test public void testDriverFailure() { when(dbModelObject.getDriver()).thenReturn("driver"); when(dbModelObject.getDatabaseURL()).thenReturn("jdbc:postgresql://127.0.0.1:5432/testdb"); when(dbModelObject.getUserName()).thenReturn("postgres"); when(dbModelObject.getPassword()).thenReturn("postgres"); try { dbConnector.connectionInit(); } catch (Exception e) { assertTrue(e instanceof ClassNotFoundException); } verify(dbModelObject).getDriver(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload