@Override public Object removeAttribute(final String id) { return context.removeAttribute(id); }
@Override public Object removeAttribute(final String id) { return context.removeAttribute(id); }
@Test public void testEmptyContextOperations() { final HttpContext currentContext = new BasicHttpContext(null); Assert.assertEquals(null, currentContext.getAttribute("param1")); currentContext.removeAttribute("param1"); Assert.assertEquals(null, currentContext.getAttribute("param1")); }
@Test public void testContextInvalidInput() throws Exception { final HttpContext currentContext = new BasicHttpContext(null); try { currentContext.setAttribute(null, null); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException ex) { // expected } try { currentContext.getAttribute(null); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException ex) { // expected } try { currentContext.removeAttribute(null); Assert.fail("IllegalArgumentException should have been thrown"); } catch (final IllegalArgumentException ex) { // expected } }
@Test public void testContextOperations() { final HttpContext parentContext = new BasicHttpContext(null); final HttpContext currentContext = new BasicHttpContext(parentContext); parentContext.setAttribute("param1", "1"); parentContext.setAttribute("param2", "2"); currentContext.setAttribute("param3", "3"); currentContext.setAttribute("param2", "4"); Assert.assertEquals("1", parentContext.getAttribute("param1")); Assert.assertEquals("2", parentContext.getAttribute("param2")); Assert.assertEquals(null, parentContext.getAttribute("param3")); Assert.assertEquals("1", currentContext.getAttribute("param1")); Assert.assertEquals("4", currentContext.getAttribute("param2")); Assert.assertEquals("3", currentContext.getAttribute("param3")); Assert.assertEquals(null, currentContext.getAttribute("param4")); currentContext.removeAttribute("param1"); currentContext.removeAttribute("param2"); currentContext.removeAttribute("param3"); currentContext.removeAttribute("param4"); Assert.assertEquals("1", currentContext.getAttribute("param1")); Assert.assertEquals("2", currentContext.getAttribute("param2")); Assert.assertEquals(null, currentContext.getAttribute("param3")); Assert.assertEquals(null, currentContext.getAttribute("param4")); }