Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * OfficeFloor - http://www.officefloor.net
   * Copyright (C) 2005-2011 Daniel Sagenschneider
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 package net.officefloor.compile.impl.section;
 
Tests the net.officefloor.compile.section.SectionLoader.

Author(s):
Daniel Sagenschneider
 
 
 	private final CompilerIssues issues = this.createMock(CompilerIssues.class);

 
 	private final SectionSourceSpecification specification = this
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see junit.framework.TestCase#setUp()
 	 */
 	protected void setUp() throws Exception {
 		MockSectionSource.reset(this.);
 	}

Ensures issue if fails to instantiate the net.officefloor.compile.spi.section.source.SectionSource.
 
 
 		final RuntimeException failure = new RuntimeException(
 				"instantiate failure");
 
 		// Record failure to instantiate
 				"Failed to instantiate " + MockSectionSource.class.getName()
 						+ " by default constructor"failure);
 
 		// Attempt to obtain specification
 		this.loadSpecification(false);
 	}

 
 	public void testFailGetSectionSpecification() {
 
 		final Error failure = new Error("specification failure");
 
 		// Record failure to instantiate
 		this.record_issue("Failed to obtain SectionSourceSpecification from "
 				+ MockSectionSource.class.getName(), failure);
 
 		// Attempt to obtain specification
 		this.loadSpecification(false);
	}

	public void testNoSectionSpecification() {
		// Record no specification returned
		this.record_issue("No SectionSourceSpecification returned from "
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

Ensures issue if fails to obtain the net.officefloor.compile.spi.section.source.SectionSourceProperty instances.
				"Fail to get section properties");
		// Record null section properties
				this..getProperties(), failure);
		this
						"Failed to obtain SectionSourceProperty instances from SectionSourceSpecification for "
MockSectionSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

Ensures considers null net.officefloor.compile.spi.section.source.SectionSourceProperty array as no properties.
		// Record null section properties
				.getProperties(), null);
		// Attempt to obtain specification
	}

Ensures issue if element in net.officefloor.compile.spi.section.source.SectionSourceProperty array is null.
		// Record null section properties
				.getProperties(), new SectionSourceProperty[] { null });
		this
				.record_issue("SectionSourceProperty 0 is null from SectionSourceSpecification for "
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

	public void testNullSectionPropertyName() {
		final SectionSourceProperty property = this
		// Record obtaining section properties
				.getProperties(), new SectionSourceProperty[] { property });
		this.recordReturn(propertyproperty.getName(), "");
		this
				.record_issue("SectionSourceProperty 0 provided blank name from SectionSourceSpecification for "
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

		final RuntimeException failure = new RuntimeException(
				"Failed to get property name");
		final SectionSourceProperty property = this
		// Record obtaining section properties
				.getProperties(), new SectionSourceProperty[] { property });
		this.control(property).expectAndThrow(property.getName(), failure);
		this
						"Failed to get name for SectionSourceProperty 0 from SectionSourceSpecification for "
MockSectionSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

Ensures issue if fails to get the net.officefloor.compile.spi.section.source.SectionSourceProperty label.
		final RuntimeException failure = new RuntimeException(
				"Failed to get property label");
		final SectionSourceProperty property = this
		// Record obtaining section properties
				.getProperties(), new SectionSourceProperty[] { property });
		this.recordReturn(propertyproperty.getName(), "NAME");
		this.control(property).expectAndThrow(property.getLabel(), failure);
		this
						"Failed to get label for SectionSourceProperty 0 (NAME) from SectionSourceSpecification for "
MockSectionSource.class.getName(), failure);
		// Attempt to obtain specification
		this.loadSpecification(false);
	}

		final SectionSourceProperty propertyWithLabel = this
		final SectionSourceProperty propertyWithoutLabel = this
		// Record obtaining section properties
				propertyWithLabelpropertyWithoutLabel });
		this.recordReturn(propertyWithLabelpropertyWithLabel.getName(),
				"NAME");
		this.recordReturn(propertyWithLabelpropertyWithLabel.getLabel(),
				"LABEL");
		this.recordReturn(propertyWithoutLabelpropertyWithoutLabel.getName(),
				"NO LABEL");
		this.recordReturn(propertyWithoutLabel,
				propertyWithoutLabel.getLabel(), null);
		// Attempt to obtain specification
		this.loadSpecification(true"NAME""LABEL""NO LABEL""NO LABEL");
	}

Records an issue.

Parameters:
issueDescription Description of the issue.
	private void record_issue(String issueDescription) {
		this..addIssue(.nullnullnull,
				issueDescription);
	}

Records an issue.

Parameters:
issueDescription Description of the issue.
cause Cause of the issue.
	private void record_issue(String issueDescriptionThrowable cause) {
		this..addIssue(.nullnullnull,
				issueDescriptioncause);
	}

Loads the net.officefloor.compile.spi.section.source.SectionSourceSpecification.

Parameters:
isExpectToLoad Flag indicating if expect to obtain the net.officefloor.compile.spi.section.source.SectionSourceSpecification.
propertyNames Expected net.officefloor.compile.properties.Property names for being returned.
	private void loadSpecification(boolean isExpectToLoad,
			String... propertyNameLabelPairs) {
		// Load the section specification
		OfficeFloorCompiler compiler = OfficeFloorCompiler
		compiler.setCompilerIssues(this.);
		SectionLoader sectionLoader = compiler.getSectionLoader();
		PropertyList propertyList = sectionLoader
		// Determine if expected to load
		if (isExpectToLoad) {
			assertNotNull("Expected to load specification"propertyList);
			// Ensure the properties are as expected
			PropertyListUtil.validatePropertyNameLabels(propertyList,
					propertyNameLabelPairs);
else {
			assertNull("Should not load specification"propertyList);
		}
	}

	public static class MockSectionSource implements SectionSource {

Failure to instantiate an instance.
		public static RuntimeException instantiateFailure = null;

		public static Error specificationFailure = null;

Resets the state for next test.

		public static void reset(SectionSourceSpecification specification) {
		}

Default constructor.
		public MockSectionSource() {
			// Determine if fail to instantiate
			if ( != null) {
			}
		}
		/*
		 * ================ SectionSource ================================
		 */
			// Determine if failure to obtain
			if ( != null) {
			}
			// Return the specification
		}
		public void sourceSection(SectionDesigner sectionBuilder,
				SectionSourceContext contextthrows Exception {
			fail("Should not be invoked for obtaining specification");
		}
	}
New to GrepCode? Check out our FAQ X