/** * Tests the proxy registration and retrieval methods. * * <p>Tests <code>registerProxy</code> and <code>retrieveProxy</code> in the same test. These * methods cannot currently be tested separately in any meaningful way other than to show that the * methods do not throw exception when called. */ @Test public void testRegisterAndRetrieveProxy() { // register a proxy and retrieve it. IModel model = Model.getInstance(); model.registerProxy(new Proxy("colors", new String[] {"red", "green", "blue"})); Proxy proxy = (Proxy) model.retrieveProxy("colors"); String[] data = (String[]) proxy.getData(); // test assertions Assert.assertNotNull("Expecting data not null", data); Assert.assertNotNull("Expecting data type is Array", (String[]) data); Assert.assertEquals("Expecting data.length == 3", data.length, 3); Assert.assertEquals("Expecting data[0] == 'red'", data[0], "red"); Assert.assertEquals("Expecting data[1] == 'green'", data[1], "green"); Assert.assertEquals("Expecting data[2] == 'blue'", data[2], "blue"); }
/** Tests the proxy removal method. */ @Test public void testRegisterAndRemoveProxy() { // register a proxy, remove it, then try to retrieve it IModel model = Model.getInstance(); IProxy proxy = new Proxy("sizes", new String[] {"7", "13", "21"}); model.registerProxy(proxy); // remove the proxy IProxy removedProxy = model.removeProxy("sizes"); // assert that we removed the appropriate proxy Assert.assertEquals( "Expecting removedProxy.getProxyName() == 'sizes'", removedProxy.getProxyName(), "sizes"); // ensure that the proxy is no longer retrievable from the model proxy = model.retrieveProxy("sizes"); // test assertions Assert.assertNull("Expecting proxy is null", proxy); }