import 'mocha' ; import { expect } from 'chai' ; import { ScriptingLanguage } from '@/domain/ScriptingLanguage' ; import { ScriptingLanguageFactory } from '@/application/Common/ScriptingLanguage/ScriptingLanguageFactory' ; import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner' ; import { ScriptingLanguageFactoryTestRunner } from './ScriptingLanguageFactoryTestRunner' ; class ScriptingLanguageConcrete extends ScriptingLanguageFactory < number > { public registerGetter ( language , getter ) { super . registerGetter ( language , getter ) ; } } describe ( 'ScriptingLanguageFactory' , ( ) => { describe ( 'registerGetter' , ( ) => { describe ( 'validates language' , ( ) => { const validValue = ScriptingLanguage . batchfile ; const getter = ( ) => undefined ; const sut = new ScriptingLanguageConcrete ( ) ; const act = ( language ) => sut . registerGetter ( language , getter ) ; new EnumRangeTestRunner ( act ) . testOutOfRangeThrows ( ) . testUndefinedValueThrows ( ) . testValidValueDoesNotThrow ( validValue ) ; } ) ; it ( 'throw when getter is undefined' , ( ) => { const expectedError = 'undefined getter' ; const language = ScriptingLanguage . batchfile ; const getter = undefined ; const sut = new ScriptingLanguageConcrete ( ) ; const act = ( ) => sut . registerGetter ( language , getter ) ; expect ( act ) . to . throw ( expectedError ) ; } ) ; it ( 'throw when language is already registered' , ( ) => { const language = ScriptingLanguage . batchfile ; const expectedError = `${ ScriptingLanguage [ language ] } is already registered` ; const getter = ( ) => undefined ; const sut = new ScriptingLanguageConcrete ( ) ; sut . registerGetter ( language , getter ) ; const reRegister = ( ) => sut . registerGetter ( language , getter ) ; expect ( reRegister ) . to . throw ( expectedError ) ; } ) ; } ) ; describe ( 'create' , ( ) => { const sut = new ScriptingLanguageConcrete ( ) ; sut . registerGetter ( ScriptingLanguage . batchfile , ( ) => undefined ) ; const runner = new ScriptingLanguageFactoryTestRunner ( ) ; runner . testCreateMethod ( sut ) ; } ) ; } ) ;