MagicUndefineGlobal implements SpecialCommand { @Override public StellarResult execute(String command, StellarShellExecutor executor) { StellarResult result; String variable = StringUtils.trimToEmpty(command.substring(MAGIC_UNDEFINE.length())); if(StringUtils.isNotBlank(variable)) { Map<String, Object> globals = executor.getGlobalConfig(); globals.remove(variable); result = noop(); } else { result = error(String.format("%s expected name of global, got '%s'", MAGIC_UNDEFINE, variable)); } return result; }  @Override String getCommand(); @Override Function<String, Boolean> getMatcher(); @Override StellarResult execute(String command, StellarShellExecutor executor); static final String MAGIC_UNDEFINE; }
@Test public void testUndefine() { executor.getGlobalConfig().put("global", 22); assertEquals(1, executor.getGlobalConfig().size()); StellarResult result = magic.execute("%undefine global", executor); assertTrue(result.isSuccess()); assertTrue(result.getValue().isPresent()); assertEquals(0, executor.getGlobalConfig().size()); }
@Test public void testWithNoVariable() { executor.getGlobalConfig().put("global", 22); assertEquals(1, executor.getGlobalConfig().size()); StellarResult result = magic.execute("%undefine", executor); assertTrue(result.isError()); assertTrue(result.getException().isPresent()); assertEquals(1, executor.getGlobalConfig().size()); }