alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (StaticScriptSourceTests.java)

This example Spring Framework source code file (StaticScriptSourceTests.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

exception, exception, illegalargumentexception, must, must, script, script, script's, script_text, staticscriptsource, staticscriptsource, staticscriptsourcetests, string, testcase

The Spring Framework StaticScriptSourceTests.java source code

/*
 * Copyright 2002-2006 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.scripting.support;

import junit.framework.TestCase;

/**
 * Unit tests for the StaticScriptSource class.
 *
 * @author Rick Evans
 */
public final class StaticScriptSourceTests extends TestCase {

	private static final String SCRIPT_TEXT = "print($hello) if $true;";


	public void testCreateWithNullScript() throws Exception {
		try {
			new StaticScriptSource(null);
			fail("Must have failed when passed a null script string.");
		}
		catch (IllegalArgumentException expected) {
		}
	}

	public void testCreateWithEmptyScript() throws Exception {
		try {
			new StaticScriptSource("");
			fail("Must have failed when passed an empty script string.");
		}
		catch (IllegalArgumentException expected) {
		}
	}

	public void testCreateWithWhitespaceOnlyScript() throws Exception {
		try {
			new StaticScriptSource("   \n\n\t  \t\n");
			fail("Must have failed when passed a whitespace-only script string.");
		}
		catch (IllegalArgumentException expected) {
		}
	}

	public void testIsModifiedIsTrueByDefault() throws Exception {
		StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
		assertTrue("Script must be flagged as 'modified' when first created.", source.isModified());
	}

	public void testGettingScriptTogglesIsModified() throws Exception {
		StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
		source.getScriptAsString();
		assertFalse("Script must be flagged as 'not modified' after script is read.", source.isModified());
	}

	public void testGettingScriptViaToStringDoesNotToggleIsModified() throws Exception {
		StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
		boolean isModifiedState = source.isModified();
		source.toString();
		assertEquals("Script's 'modified' flag must not change after script is read via toString().", isModifiedState, source.isModified());
	}

	public void testIsModifiedToggledWhenDifferentScriptIsSet() throws Exception {
		StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
		source.setScript("use warnings;");
		assertTrue("Script must be flagged as 'modified' when different script is passed in.", source.isModified());
	}

	public void testIsModifiedNotToggledWhenSameScriptIsSet() throws Exception {
		StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
		source.setScript(SCRIPT_TEXT);
		assertFalse("Script must not be flagged as 'modified' when same script is passed in.", source.isModified());
	}

}

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework StaticScriptSourceTests.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.