@@ -104,32 +104,45 @@ describe('ModelUtil', function () {
104104 } ) ;
105105
106106 describe ( '#isAssignableTo' , function ( ) {
107+ let mockModelFile ;
108+ let mockProperty ;
107109
108- it ( 'throws error for primitive types' , function ( ) {
109- let mockModelFile = sinon . createStubInstance ( ModelFile ) ;
110- let mockProperty = sinon . createStubInstance ( Property ) ;
111- ( ( ) => {
112- ModelUtil . isAssignableTo ( mockModelFile , 'String' , mockProperty ) ;
113- } ) . should . throw ( / T h i s m e t h o d o n l y w o r k s w i t h c o m p l e x t y p e s / ) ;
110+ beforeEach ( function ( ) {
111+ mockModelFile = sinon . createStubInstance ( ModelFile ) ;
112+ mockProperty = sinon . createStubInstance ( Property ) ;
113+ } ) ;
114+
115+ it ( 'returns true for matching primitive types' , function ( ) {
116+ mockProperty . getFullyQualifiedTypeName . returns ( 'String' ) ;
117+ const result = ModelUtil . isAssignableTo ( mockModelFile , 'String' , mockProperty ) ;
118+ result . should . equal ( true ) ;
119+ } ) ;
120+
121+ it ( 'returns false for non-matching primitive types' , function ( ) {
122+ mockProperty . getFullyQualifiedTypeName . returns ( 'DateTime' ) ;
123+ const result = ModelUtil . isAssignableTo ( mockModelFile , 'Boolean' , mockProperty ) ;
124+ result . should . equal ( false ) ;
125+ } ) ;
126+
127+ it ( 'returns false for assignment of primitive to non-primitive property' , function ( ) {
128+ mockProperty . getFullyQualifiedTypeName . returns ( 'org.doge.Doge' ) ;
129+ const result = ModelUtil . isAssignableTo ( mockModelFile , 'String' , mockProperty ) ;
130+ result . should . equal ( false ) ;
114131 } ) ;
115132
116- it ( 'returns false if property name is primitive type' , function ( ) {
117- let mockModelFile = sinon . createStubInstance ( ModelFile ) ;
118- let mockProperty = sinon . createStubInstance ( Property ) ;
119- mockProperty . getName . returns ( 'String' ) ;
120- ModelUtil . isAssignableTo ( mockModelFile , 'org.doge.Doge' , mockProperty ) . should . equal ( false ) ;
133+ it ( 'returns false for assignment of non-primitive to primitive property' , function ( ) {
134+ mockProperty . getFullyQualifiedTypeName . returns ( 'String' ) ;
135+ const result = ModelUtil . isAssignableTo ( mockModelFile , 'org.doge.Doge' , mockProperty ) ;
136+ result . should . equal ( false ) ;
121137 } ) ;
122138
123139 it ( 'returns true if property type and required type are identical' , function ( ) {
124- let mockModelFile = sinon . createStubInstance ( ModelFile ) ;
125- let mockProperty = sinon . createStubInstance ( Property ) ;
126140 mockProperty . getFullyQualifiedTypeName . returns ( 'org.doge.Doge' ) ;
127- ModelUtil . isAssignableTo ( mockModelFile , 'org.doge.Doge' , mockProperty ) . should . equal ( true ) ;
141+ const result = ModelUtil . isAssignableTo ( mockModelFile , 'org.doge.Doge' , mockProperty ) ;
142+ result . should . equal ( true ) ;
128143 } ) ;
129144
130145 it ( 'throws error when type cannot be found' , function ( ) {
131- let mockModelFile = sinon . createStubInstance ( ModelFile ) ;
132- let mockProperty = sinon . createStubInstance ( Property ) ;
133146 mockProperty . getName . returns ( 'theDoge' ) ;
134147 mockProperty . getFullyQualifiedTypeName . returns ( 'org.doge.BaseDoge' ) ;
135148 mockModelFile . getType . returns ( null ) ;
0 commit comments