diff --git a/src/app/converter-registry.service.ts b/src/app/converter-registry.service.ts index 56e488d..d84733b 100644 --- a/src/app/converter-registry.service.ts +++ b/src/app/converter-registry.service.ts @@ -18,8 +18,8 @@ import {URIComponentDecoder} from './converter/uricomponent-decoder'; import {URIComponentEncoder} from './converter/uricomponent-encoder'; import {URIDecoder} from './converter/uridecoder'; import {URIEncoder} from './converter/uriencoder'; -import {UTF8Decoder} from './converter/utf8decoder'; -import {UTF8Encoder} from './converter/utf8encoder'; +import {UTF8Decoder} from './converter/utf8-decoder'; +import {UTF8Encoder} from './converter/utf8-encoder'; @Injectable({ providedIn: 'root' diff --git a/src/app/converter/utf8-decoder.spec.ts b/src/app/converter/utf8-decoder.spec.ts new file mode 100644 index 0000000..7eaf5c2 --- /dev/null +++ b/src/app/converter/utf8-decoder.spec.ts @@ -0,0 +1,33 @@ +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; +import {UTF8Decoder} from './utf8-decoder'; +import createSpyObj = jasmine.createSpyObj; +import Spy = jasmine.Spy; + +describe('UTF8Decoder', () => { + let sut: UTF8Decoder; + let nativeWrapperSpy: Partial; + let decodeSpy: Spy; + + beforeEach(() => { + nativeWrapperSpy = {utf8: createSpyObj(['decode'])}; + decodeSpy = nativeWrapperSpy.utf8.decode as Spy; + sut = new UTF8Decoder((nativeWrapperSpy as NativeLibraryWrapperService)); + }); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "decodeutf8"', () => { + expect(sut.getId()).toEqual('decodeutf8'); + }); + + it('should call through to the native UTF-8 decoder', () => { + const testInput = 'My input'; + const expectedOutput = 'It worked'; + decodeSpy.and.returnValue(expectedOutput); + const result: string = sut.convert(testInput); + expect(result).toEqual(expectedOutput); + expect(decodeSpy).toHaveBeenCalledWith(testInput); + }); +}); diff --git a/src/app/converter/utf8decoder.ts b/src/app/converter/utf8-decoder.ts similarity index 100% rename from src/app/converter/utf8decoder.ts rename to src/app/converter/utf8-decoder.ts diff --git a/src/app/converter/utf8-encoder.spec.ts b/src/app/converter/utf8-encoder.spec.ts new file mode 100644 index 0000000..334a26b --- /dev/null +++ b/src/app/converter/utf8-encoder.spec.ts @@ -0,0 +1,33 @@ +import {NativeLibraryWrapperService} from '../native-library-wrapper.service'; +import {UTF8Encoder} from './utf8-encoder'; +import createSpyObj = jasmine.createSpyObj; +import Spy = jasmine.Spy; + +describe('UTF8Encoder', () => { + let sut: UTF8Encoder; + let nativeWrapperSpy: Partial; + let encodeSpy: Spy; + + beforeEach(() => { + nativeWrapperSpy = {utf8: createSpyObj(['encode'])}; + encodeSpy = nativeWrapperSpy.utf8.encode as Spy; + sut = new UTF8Encoder(nativeWrapperSpy as NativeLibraryWrapperService); + }); + + it('should create an instance', () => { + expect(sut).toBeTruthy(); + }); + + it('should have the id "encodeutf8"', () => { + expect(sut.getId()).toEqual('encodeutf8'); + }); + + it('should call through to the native UTF-8 encoder', () => { + const testInput = 'My input'; + const expectedOutput = 'It worked'; + encodeSpy.and.returnValue(expectedOutput); + const result: string = sut.convert(testInput); + expect(result).toEqual(expectedOutput); + expect(encodeSpy).toHaveBeenCalledWith(testInput); + }); +}); diff --git a/src/app/converter/utf8encoder.ts b/src/app/converter/utf8-encoder.ts similarity index 100% rename from src/app/converter/utf8encoder.ts rename to src/app/converter/utf8-encoder.ts