/** Tests the hasProxy Method */ @Test public void testHasProxy() { // register a proxy IModel model = Model.getInstance(); IProxy proxy = new Proxy("aces", new String[] {"clubs", "spades", "hearts", "diamonds"}); model.registerProxy(proxy); // assert that the model.hasProxy method returns true // for that proxy name Assert.assertTrue("Expecting model.hasProxy('aces') == true", model.hasProxy("aces")); // remove the proxy model.removeProxy("aces"); // assert that the model.hasProxy method returns false // for that proxy name Assert.assertFalse("Expecting model.hasProxy('aces') == false", model.hasProxy("aces")); }
/** 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); }
/** Tests that the Model calls the onRegister and onRemove methods */ public void testOnRegisterAndOnRemove() { // Get a Singleton View instance IModel model = Model.getInstance(); // Create and register the test mediator IProxy proxy = new ModelTestProxy(); model.registerProxy(proxy); // assert that onRegsiter was called, and the proxy responded by setting its data accordingly Assert.assertEquals( "Expecting proxy.getData() == ModelTestProxy.ON_REGISTER_CALLED", proxy.getData(), ModelTestProxy.ON_REGISTER_CALLED); // Remove the component model.removeProxy(ModelTestProxy.NAME); // assert that onRemove was called, and the proxy responded by setting its data accordingly Assert.assertEquals( "Expecting proxy.getData() == ModelTestProxy.ON_REMOVE_CALLED", proxy.getData(), ModelTestProxy.ON_REMOVE_CALLED); }