From bb9eb16fd3674c981459d930d1d21058456d2645 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Fri, 21 Oct 2011 09:57:14 -0400 Subject: [PATCH] [#25] Began adding MemberBuilder/VisibilityTest to test MemberBuilder directly As mentioned in a prior commit blog-like entry, many of the tests evolved into more of an integration or system-level type of test. Let's get away from that. --- test/MemberBuilder/VisibilityTest.js | 108 +++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 test/MemberBuilder/VisibilityTest.js diff --git a/test/MemberBuilder/VisibilityTest.js b/test/MemberBuilder/VisibilityTest.js new file mode 100644 index 0000000..57bdda8 --- /dev/null +++ b/test/MemberBuilder/VisibilityTest.js @@ -0,0 +1,108 @@ +/** + * Tests visibility portion of member builder + * + * Copyright (C) 2010 Mike Gerwitz + * + * This file is part of ease.js. + * + * ease.js is free software: you can redistribute it and/or modify it under the + * terms of the GNU Lesser 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 Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * @author Mike Gerwitz + * @package test + */ + +function buildStubMethod( name, val, visibility ) +{ + var keywords = {}; + + // set visibility level using access modifier + keywords[ visibility ] = true; + + this.sut.buildMethod( this.members, {}, name, + function() { + return val; + }, + keywords, + function() {}, + 1, + {} + ); +} + + +function buildStubProp( name, val, visibility ) +{ + var keywords = {}; + + // set visibility level using access modifier + keywords[ visibility ] = true; + + this.sut.buildProp( this.members, {}, name, val, keywords, {} ); +} + + +require( 'common' ).testCase( +{ + caseSetUp: function() + { + this.buildStubMethod = function() + { + buildStubMethod.apply( this, arguments ); + }; + + this.buildStubProp = function() + { + buildStubProp.apply( this, arguments ); + }; + }, + + + setUp: function() + { + // stub factories used for testing + var stubFactory = this.require( 'MethodWrapperFactory' )( + function( func ) { return func; } + ); + + this.sut = this.require( 'MemberBuilder' )( + stubFactory, stubFactory + ); + + this.members = this.sut.initMembers(); + }, + + + 'Public properties are accessible via the public interface': function() + { + var name = 'pub', + val = 'val'; + + this.buildStubProp( name, val, 'public' ); + this.assertEqual( this.members[ 'public' ][ name ][ 0 ], val ); + }, + + + 'Public methods are accessible via the public interface': function() + { + var name = 'pub', + val = 'val'; + + this.buildStubMethod( name, val, 'public' ); + + this.assertEqual( + this.members[ 'public' ][ name ](), + val + ); + }, +} );