public void testReturnBlockThrows() { Exception expected = null; final Exception orig = new Exception("test"); Exceptions.Block block = new Exceptions.Block() { public Object inner() throws Exception { throw orig; } }; try { block.exec(); } catch (Exception e) { expected = e; } assertNotNull(expected); assertEquals(orig, expected.getCause()); }
synchronized String pid() { if (pid == null) { if (!pidFile().exists()) { return "No PID"; } Exceptions.Block block = new Exceptions.Block() { public Object inner() throws IOException { return fileUtil.asString(pidFile()).trim(); } }; pid = (String) block.exec(); } return pid; }
@Override public Process exec(final String[] cmdarray, final String[] envp, final File dir) { Exceptions.Block block = new Exceptions.Block() { @Override protected Object inner() throws Exception { return runtime.exec(cmdarray, envp, dir); } }; return (Process) block.exec(); }
public void testReturnBlock() { final String expected = "foo"; Exceptions.Block block = new Exceptions.Block() { public Object inner() throws Exception { return expected; } }; String actual = (String) block.exec(); assertEquals(expected, actual); }
private String getStringAttribute(final String key) { if (!attributes.containsKey(key)) { return null; } Exceptions.Block block = new Exceptions.Block() { protected Object inner() throws Exception { return getAttribute(key); } }; return (String) block.exec(); } }
public Process exec(final String[] cmdarray, final String[] envp, final File dir) { Exceptions.Block block = new Exceptions.Block() { protected Object inner() throws Exception { return runtime.exec(cmdarray, envp, dir); } }; return (Process) block.exec(); }
private Object invokeStart() { Exceptions.Block block = new Exceptions.Block() { public Object inner() throws Exception { return invoke(START_METHOD, null, null); } }; return block.exec(); } }