/** * Test method for {@link org.sakaiproject.evaluation.logic.EvalSettingsImpl#set(java.lang.String, * java.lang.Object)}. */ @Test public void testSet() { // set a real value using a constant Assert.assertEquals(true, evalSettings.set(EvalSettings.FROM_EMAIL_ADDRESS, TEST_VALUE1)); String s = (String) evalSettings.get(EvalSettings.FROM_EMAIL_ADDRESS); Assert.assertNotNull(s); Assert.assertEquals(s, TEST_VALUE1); // set the test value to a new value Assert.assertEquals(true, evalSettings.set(TEST_CONSTANT1, TEST_VALUE2)); s = (String) evalSettings.get(TEST_CONSTANT1); Assert.assertNotNull(s); Assert.assertEquals(s, TEST_VALUE2); // set test value using optional string method Assert.assertEquals(true, evalSettings.set(TEST_NAME2, TEST_VALUE1)); s = (String) evalSettings.get(TEST_NAME2); // use optional string method to retrieve Assert.assertNotNull(s); Assert.assertEquals(s, TEST_VALUE1); // test clearing the test value Assert.assertEquals(true, evalSettings.set(TEST_CONSTANT3, null)); s = (String) evalSettings.get(TEST_CONSTANT3); Assert.assertNull(s); // NOT CURRENTLY SUPPORTED // // now attempt to set an invalid constant // try { // Assert.assertFalse( evalSettings.set(INVALID_CONSTANT, TEST_VALUE1) ); // Assert.fail("Should have thrown an illegal argument exception"); // } catch (IllegalArgumentException e) { // Assert.assertNotNull(e); // } // now attempt to set an invalid value try { evalSettings.set(TEST_CONSTANT1, Boolean.TRUE); Assert.fail("Should have thrown an illegal argument exception"); } catch (IllegalArgumentException e) { Assert.assertNotNull(e); } }
/** * Test method for {@link * org.sakaiproject.evaluation.logic.EvalSettingsImpl#get(java.lang.String)}. */ @Test public void testGet() { // get a real value using a constant String s = (String) evalSettings.get(EvalSettings.FROM_EMAIL_ADDRESS); Assert.assertNotNull(s); Assert.assertTrue(s.length() > 0); // get the test value s = (String) evalSettings.get(TEST_CONSTANT1); Assert.assertNotNull(s); Assert.assertEquals(s, TEST_VALUE1); s = (String) evalSettings.get(TEST_CONSTANT3); Assert.assertNotNull(s); Assert.assertEquals(s, TEST_VALUE3); // get the test value (optional String only method) s = (String) evalSettings.get(TEST_NAME1); Assert.assertNotNull(s); Assert.assertEquals(s, TEST_VALUE1); // attempt to get the wrong object try { Boolean b = (Boolean) evalSettings.get(TEST_CONSTANT1); b.booleanValue(); Assert.fail("Should have thrown a cast exception"); } catch (ClassCastException e) { Assert.assertNotNull(e); } // attempt to get a non-existent item s = (String) evalSettings.get(INVALID_CONSTANT); Assert.assertNull(s); // non-existent items return a null // attempt to get an empty string try { s = (String) evalSettings.get(""); Assert.fail("Should have thrown an illegal argument exception"); } catch (IllegalArgumentException e) { Assert.assertNotNull(e); } // attempt to get a null try { s = (String) evalSettings.get(null); Assert.fail("Should have thrown an illegal argument exception"); } catch (IllegalArgumentException e) { Assert.assertNotNull(e); } }