incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s9tpep...@apache.org
Subject svn commit: r1231917 - in /incubator/flex/whiteboard/s9tpepper/validators: ./ src-tests/ src-tests/org/ src-tests/org/apache/ src-tests/org/apache/flex/ src-tests/org/apache/flex/validators/ src/ src/org/ src/org/apache/ src/org/apache/flex/ src/org/ap...
Date Mon, 16 Jan 2012 11:00:35 GMT
Author: s9tpepper
Date: Mon Jan 16 11:00:35 2012
New Revision: 1231917

URL: http://svn.apache.org/viewvc?rev=1231917&view=rev
Log:
Adding my Spark based StringValidator to my whiteboard.

Added:
    incubator/flex/whiteboard/s9tpepper/validators/
    incubator/flex/whiteboard/s9tpepper/validators/src/
    incubator/flex/whiteboard/s9tpepper/validators/src-tests/
    incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/
    incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/apache/
    incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/apache/flex/
    incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/apache/flex/validators/
    incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/apache/flex/validators/StringValidatorTests.as
  (with props)
    incubator/flex/whiteboard/s9tpepper/validators/src/org/
    incubator/flex/whiteboard/s9tpepper/validators/src/org/apache/
    incubator/flex/whiteboard/s9tpepper/validators/src/org/apache/flex/
    incubator/flex/whiteboard/s9tpepper/validators/src/org/apache/flex/validators/
    incubator/flex/whiteboard/s9tpepper/validators/src/org/apache/flex/validators/StringValidator.as
  (with props)

Added: incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/apache/flex/validators/StringValidatorTests.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/apache/flex/validators/StringValidatorTests.as?rev=1231917&view=auto
==============================================================================
--- incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/apache/flex/validators/StringValidatorTests.as
(added)
+++ incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/apache/flex/validators/StringValidatorTests.as
Mon Jan 16 11:00:35 2012
@@ -0,0 +1,129 @@
+package org.apache.flex.validators
+{
+	import mx.events.ValidationResultEvent;
+	import mx.validators.ValidationResult;
+
+	import org.flexunit.asserts.assertEquals;
+	import org.flexunit.asserts.assertNotNull;
+	import org.flexunit.asserts.assertNull;
+	import org.flexunit.asserts.assertTrue;
+	import org.flexunit.asserts.fail;
+
+	import spark.validators.NumberValidator;
+	import spark.validators.supportClasses.GlobalizationValidatorBase;
+
+	public class StringValidatorTests
+	{
+
+		[Before]
+		public function setUp():void
+		{
+		}
+
+		private function setUpMinCharsErrorValidation():StringValidator
+		{
+			const testSource:Object               = {testProperty: "123"};
+
+			const stringValidator:StringValidator = new StringValidator();
+			stringValidator.source = testSource;
+			stringValidator.property = "testProperty";
+			stringValidator.minChars = 4;
+			return stringValidator;
+		}
+
+		private function setUpMaxCharsErrorValidation():StringValidator
+		{
+			const stringValidator:StringValidator = new StringValidator();
+			const testObject:Object               = {testProperty: "12345"};
+			stringValidator.source = testObject;
+			stringValidator.property = "testProperty";
+			stringValidator.maxChars = 4;
+			return stringValidator;
+		}
+
+		[Test]
+		public function StringValidator_onInstantiation_extendsGlobalizationValidatorBase():void
+		{
+			const stringValidator:StringValidator = new StringValidator();
+
+			assertTrue(stringValidator is GlobalizationValidatorBase);
+		}
+
+		[Test]
+		public function StringValidator_onInstantiation_minCharsErrorIsSetToDefaultConstant():void
+		{
+			const stringValidator:StringValidator = new StringValidator();
+
+			assertEquals(StringValidator.DEFAULT_MIN_CHARS_ERROR, stringValidator.minCharsError);
+		}
+
+		[Test]
+		public function StringValidator_onInstantiation_maxCharsErrorIsSetToDefaultConstant():void
+		{
+			const stringValidator:StringValidator = new StringValidator();
+
+			assertEquals(StringValidator.DEFAULT_MAX_CHARS_ERROR, stringValidator.maxCharsError);
+		}
+
+		[Test]
+		public function validate_sourcePropertyIsLessThanMinChars_ValidationResultEventResultsAreNotNull():void
+		{
+			const stringValidator:StringValidator             = setUpMinCharsErrorValidation();
+
+			const validationResultEvent:ValidationResultEvent = stringValidator.validate(null, false);
+
+			assertNotNull(validationResultEvent.results);
+		}
+
+		[Test]
+		public function validate_sourcePropertyIsLessThanMinChars_ValidationResultEventResultMessageIsSetToMinCharsError():void
+		{
+			const stringValidator:StringValidator             = setUpMinCharsErrorValidation();
+			const validationResultEvent:ValidationResultEvent = stringValidator.validate(null, false);
+
+			const validationResult:ValidationResult           = validationResultEvent.results[0] as
ValidationResult;
+
+			assertEquals(stringValidator.minCharsError, validationResult.errorMessage);
+		}
+
+		[Test]
+		public function validate_sourcePropertyIsGreaterThanMaxChars_ValidationResultEventResultsAreNotNull():void
+		{
+			const stringValidator:StringValidator             = setUpMaxCharsErrorValidation();
+
+			const validationResultEvent:ValidationResultEvent = stringValidator.validate(null, false);
+
+			assertNotNull(validationResultEvent.results);
+		}
+
+		[Test]
+		public function validate_sourcePropertyIsGreaterThanMaxChars_ValidationResultEventResultMessageIsSetToMaxCharsError():void
+		{
+			const stringValidator:StringValidator             = setUpMaxCharsErrorValidation();
+			const validationResultEvent:ValidationResultEvent = stringValidator.validate(null, false);
+
+			const validationResult:ValidationResult           = validationResultEvent.results[0] as
ValidationResult;
+
+			assertEquals(stringValidator.maxCharsError, validationResult.errorMessage);
+		}
+
+		[Test]
+		public function validate_maxCharsIsNegativeOne_validationResultEventResultsIsNull():void
+		{
+			const testObject:Object                           = {testProperty: "12"};
+			const stringValidator:StringValidator             = new StringValidator();
+			stringValidator.source = testObject;
+			stringValidator.property = "testProperty";
+			stringValidator.maxChars = -1;
+
+			const validationResultEvent:ValidationResultEvent = stringValidator.validate(null, false);
+
+			assertNull(validationResultEvent.results);
+		}
+
+		[After]
+		public function tearDown():void
+		{
+		}
+	}
+}

Propchange: incubator/flex/whiteboard/s9tpepper/validators/src-tests/org/apache/flex/validators/StringValidatorTests.as
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/flex/whiteboard/s9tpepper/validators/src/org/apache/flex/validators/StringValidator.as
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/s9tpepper/validators/src/org/apache/flex/validators/StringValidator.as?rev=1231917&view=auto
==============================================================================
--- incubator/flex/whiteboard/s9tpepper/validators/src/org/apache/flex/validators/StringValidator.as
(added)
+++ incubator/flex/whiteboard/s9tpepper/validators/src/org/apache/flex/validators/StringValidator.as
Mon Jan 16 11:00:35 2012
@@ -0,0 +1,106 @@
+package org.apache.flex.validators
+{
+	import mx.validators.ValidationResult;
+
+	import spark.validators.supportClasses.GlobalizationValidatorBase;
+
+	public class StringValidator extends GlobalizationValidatorBase
+	{
+		public static var DEFAULT_MIN_CHARS_ERROR:String = "The string does not meet the minimum
character requirement.";
+		public static var DEFAULT_MAX_CHARS_ERROR:String = "The string exceeds the maximum character
requirement.";
+
+		private var _maxChars:int;
+		private var _minChars:int;
+		private var _minCharsError:String                = DEFAULT_MIN_CHARS_ERROR;
+		private var _maxCharsError:String                = DEFAULT_MAX_CHARS_ERROR;
+
+		public function StringValidator()
+		{
+			super();
+		}
+
+		public function get maxCharsError():String
+		{
+			return _maxCharsError;
+		}
+
+		public function set maxCharsError(value:String):void
+		{
+			_maxCharsError = value;
+		}
+
+		public function get maxChars():int
+		{
+			return _maxChars;
+		}
+
+		public function set maxChars(value:int):void
+		{
+			_maxChars = value;
+		}
+
+		public function get minCharsError():String
+		{
+			return _minCharsError;
+		}
+
+		public function set minCharsError(value:String):void
+		{
+			_minCharsError = value;
+		}
+
+		public function get minChars():int
+		{
+			return _minChars;
+		}
+
+		public function set minChars(value:int):void
+		{
+			_minChars = value;
+		}
+
+		override protected function doValidation(value:Object):Array
+		{
+			const results:Array = super.doValidation(value);
+
+			validateMinChars(value, results);
+			validateMaxChars(value, results);
+
+			return results;
+		}
+
+		protected function validateMaxChars(value:Object, results:Array):void
+		{
+			if (valueDoesNotMeetMaxChars(value) && maxCharsIsNotDisabled())
+				results[results.length] = new ValidationResult(true, "", "", maxCharsError);
+		}
+
+		protected function maxCharsIsNotDisabled():Boolean
+		{
+			return maxChars != -1;
+		}
+
+		protected function valueDoesNotMeetMaxChars(value:Object):Boolean
+		{
+			const valueToValidate:String = value as String;
+			return !(valueToValidate && valueToValidate.length <= maxChars);
+		}
+
+		protected function validateMinChars(value:Object, results:Array):void
+		{
+			if (valueDoesNotMeetMinChars(value))
+				results[results.length] = createMinCharValidationResult();
+		}
+
+		protected function valueDoesNotMeetMinChars(value:Object):Boolean
+		{
+			const valueToValidate:String = value as String;
+			return !(valueToValidate && valueToValidate.length > minChars);
+		}
+
+		protected function createMinCharValidationResult():ValidationResult
+		{
+			return new ValidationResult(true, "", "", minCharsError);
+		}
+	}
+}

Propchange: incubator/flex/whiteboard/s9tpepper/validators/src/org/apache/flex/validators/StringValidator.as
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message