NvaDaemon implements Daemon { @Override public void init(DaemonContext daemonContext) throws DaemonInitException { Preconditions.checkNotNull(daemonContext, "daemonContext cannot be null"); try { this.configuration = parseArguments(daemonContext.getArguments()); } catch (ConfigurationException e) { throw new DaemonInitException("Error processing command line arguments", e); } } NvaDaemon(); @Override void init(DaemonContext daemonContext); @Override void start(); @Override synchronized void stop(); @Override void destroy();  }
@Test void testNullDaemonContext() { NvaDaemon nvaDaemon = new NvaDaemon(); Assertions.assertThrows(NullPointerException.class, () -> nvaDaemon.init(null)); }
@Test void testInvalidArguments() { NvaDaemon nvaDaemon = new NvaDaemon(); DaemonContext daemonContext = new DaemonContext() { @Override public DaemonController getController() { return null; } @Override public String[] getArguments() { return new String[0]; } }; Assertions.assertThrows(DaemonInitException.class, () -> nvaDaemon.init(daemonContext)); }
@Test void test_no_command_line_args() { NvaDaemon nvaDaemon = new NvaDaemon(); DaemonContext daemonContext = new DaemonContext() { @Override public DaemonController getController() { return null; } @Override public String[] getArguments() { return new String[0]; } }; try { nvaDaemon.init(daemonContext); } catch (DaemonInitException e) { Assertions.assertTrue(e.getMessageWithCause().contains( "Error parsing command line arguments")); } }
@Test void test_no_config_file_specified() { NvaDaemon nvaDaemon = new NvaDaemon(); DaemonContext daemonContext = new DaemonContext() { @Override public DaemonController getController() { return null; } @Override public String[] getArguments() { return new String[] { "-c" }; } }; try { nvaDaemon.init(daemonContext); } catch (DaemonInitException e) { Assertions.assertTrue(e.getMessageWithCause().contains( "Error parsing command line arguments")); } }
@Test void test_non_existent_config_file_specified() { NvaDaemon nvaDaemon = new NvaDaemon(); DaemonContext daemonContext = new DaemonContext() { @Override public DaemonController getController() { return null; } @Override public String[] getArguments() { return new String[] { "-c", testOutputDirectory + "/does-not-exist.json" }; } }; try { nvaDaemon.init(daemonContext); } catch (DaemonInitException e) { Assertions.assertTrue(e.getMessageWithCause().contains( "Error reading configuration file")); } }
@Test void test_valid_config_file_specified() throws DaemonInitException { NvaDaemon nvaDaemon = new NvaDaemon(); DaemonContext daemonContext = new DaemonContext() { @Override public DaemonController getController() { return null; } @Override public String[] getArguments() { return new String[] { "-c", testOutputDirectory + "/nvadaemon-sample.json" }; } }; nvaDaemon.init(daemonContext); }