Fix naming, add tests #5

Merged
manuel merged 19 commits from feature/use-proper-dirstructure into develop 2018-09-01 01:34:35 +02:00
5 changed files with 68 additions and 2 deletions
Showing only changes of commit 31c60f12a7 - Show all commits

View file

@ -18,8 +18,8 @@ import {URIComponentDecoder} from './converter/uricomponent-decoder';
import {URIComponentEncoder} from './converter/uricomponent-encoder'; import {URIComponentEncoder} from './converter/uricomponent-encoder';
import {URIDecoder} from './converter/uridecoder'; import {URIDecoder} from './converter/uridecoder';
import {URIEncoder} from './converter/uriencoder'; import {URIEncoder} from './converter/uriencoder';
import {UTF8Decoder} from './converter/utf8decoder'; import {UTF8Decoder} from './converter/utf8-decoder';
import {UTF8Encoder} from './converter/utf8encoder'; import {UTF8Encoder} from './converter/utf8-encoder';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'

View file

@ -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<NativeLibraryWrapperService>;
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);
});
});

View file

@ -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<NativeLibraryWrapperService>;
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);
});
});