feature/upgrade #12
2 changed files with 31 additions and 6 deletions
|
@ -1,15 +1,40 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ConverterRegistryService} from './converter-registry.service';
|
||||
import {NativeLibraryWrapperService} from './native-library-wrapper.service';
|
||||
import {Converter} from './converter/converter';
|
||||
import {Base64Decoder} from './converter/base64-decoder';
|
||||
import createSpyObj = jasmine.createSpyObj;
|
||||
|
||||
describe('ConverterRegistryService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ConverterRegistryService]
|
||||
providers: [
|
||||
ConverterRegistryService,
|
||||
{provide: NativeLibraryWrapperService, useValue: createSpyObj(['punycode', 'quotedPrintable', 'utf8'])}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ConverterRegistryService], (service: ConverterRegistryService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
|
||||
it('should register converters upon creation', inject([ConverterRegistryService], (service: ConverterRegistryService) => {
|
||||
expect(service.getAllConverters()).toBeTruthy();
|
||||
expect(service.getAllConverters().length).toBeGreaterThan(0);
|
||||
}));
|
||||
|
||||
it('must not allow the same converter ID to be regisgered more than once',
|
||||
inject([ConverterRegistryService], (service: ConverterRegistryService) => {
|
||||
// arrange
|
||||
const duplicateConverter: Converter = new Base64Decoder();
|
||||
const duplicateConverterId = duplicateConverter.getId();
|
||||
expect(() => {
|
||||
// act
|
||||
(service as any).registerConverter(duplicateConverter);
|
||||
})
|
||||
// assert
|
||||
.toThrowError(`Converter-ID ${duplicateConverterId} is already registered!`);
|
||||
}));
|
||||
});
|
||||
|
|
|
@ -7,9 +7,9 @@ import * as NativeUtf8 from 'utf8';
|
|||
providedIn: 'root'
|
||||
})
|
||||
export class NativeLibraryWrapperService {
|
||||
public utf8: Utf8;
|
||||
public quotedPrintable: QuotedPrintable;
|
||||
public punycode: Punycode;
|
||||
public readonly utf8: Utf8;
|
||||
public readonly quotedPrintable: QuotedPrintable;
|
||||
public readonly punycode: Punycode;
|
||||
|
||||
constructor() {
|
||||
this.utf8 = NativeUtf8;
|
||||
|
|
Loading…
Reference in a new issue