### Question:
GetVarPlugin extends WebHarvestPlugin { public Variable executePlugin(DynamicScopeContext context) { final String varName = evaluateAttribute(ATTR_VAR, context); final Variable value = context.getVar(varName); if (value == null) { throw new VariableException(MessageFormat.format("Variable ''{0}'' is not defined!", varName)); } this.setProperty("Var", varName); return value; }  Variable executePlugin(DynamicScopeContext context);  }### Answer:
@Test public void testExecutePlugin() throws Exception { contextMock.returns(new NodeVariable(123)).getVar("x"); ReflectionAssert.assertReflectionEquals( new NodeVariable(123), createPlugin(XmlNodeTestUtils.createXmlNode("<get var='x'/>", XmlNodeTestUtils.NAMESPACE_21), GetVarPlugin.class).executePlugin(contextMock.getMock())); contextMock.assertInvoked().getVar("x"); }
@Test public void testExecutePlugin_null() throws Exception { contextMock.returns(EmptyVariable.INSTANCE).getVar("empty"); Assert.assertSame( createPlugin(XmlNodeTestUtils.createXmlNode("<get var='empty'/>", XmlNodeTestUtils.NAMESPACE_21), GetVarPlugin.class).executePlugin(contextMock.getMock()), EmptyVariable.INSTANCE); contextMock.assertInvoked().getVar("empty"); }
@Test public void testExecutePlugin_templateAsVarName() throws Exception { final NodeVariable v123 = new NodeVariable(123); contextMock. returns(v123). getVar("x7"); contextMock. returns(asList(new KeyValuePair<Variable>("x7", v123)).iterator()). iterator(); Assert.assertEquals( createPlugin(XmlNodeTestUtils.createXmlNode("<get var='x${5+2}'/>", XmlNodeTestUtils.NAMESPACE_21), GetVarPlugin.class).executePlugin(contextMock.getMock()), v123); contextMock.assertInvoked().getVar("x7"); }
@Test(expectedExceptions = VariableException.class) public void testExecutePlugin_notDefined() throws Exception { createPlugin(XmlNodeTestUtils.createXmlNode("<get var='not defined'/>", XmlNodeTestUtils.NAMESPACE_21), GetVarPlugin.class).executePlugin(contextMock.getMock()); }