Browse Source

Implement spec for ConverterRegistryService

tags/v1.3.1-1
Manuel Friedli 1 year ago
parent
commit
2b08ab1b58

+ 28
- 3
src/app/converter-registry.service.spec.ts View File

@@ -1,15 +1,40 @@
1
-import { TestBed, inject } from '@angular/core/testing';
1
+import {inject, TestBed} from '@angular/core/testing';
2 2
 
3
-import { ConverterRegistryService } from './converter-registry.service';
3
+import {ConverterRegistryService} from './converter-registry.service';
4
+import {NativeLibraryWrapperService} from './native-library-wrapper.service';
5
+import {Converter} from './converter/converter';
6
+import {Base64Decoder} from './converter/base64-decoder';
7
+import createSpyObj = jasmine.createSpyObj;
4 8
 
5 9
 describe('ConverterRegistryService', () => {
6 10
   beforeEach(() => {
7 11
     TestBed.configureTestingModule({
8
-      providers: [ConverterRegistryService]
12
+      providers: [
13
+        ConverterRegistryService,
14
+        {provide: NativeLibraryWrapperService, useValue: createSpyObj(['punycode', 'quotedPrintable', 'utf8'])}
15
+      ]
9 16
     });
10 17
   });
11 18
 
12 19
   it('should be created', inject([ConverterRegistryService], (service: ConverterRegistryService) => {
13 20
     expect(service).toBeTruthy();
14 21
   }));
22
+
23
+  it('should register converters upon creation', inject([ConverterRegistryService], (service: ConverterRegistryService) => {
24
+    expect(service.getAllConverters()).toBeTruthy();
25
+    expect(service.getAllConverters().length).toBeGreaterThan(0);
26
+  }));
27
+
28
+  it('must not allow the same converter ID to be regisgered more than once',
29
+    inject([ConverterRegistryService], (service: ConverterRegistryService) => {
30
+      // arrange
31
+      const duplicateConverter: Converter = new Base64Decoder();
32
+      const duplicateConverterId = duplicateConverter.getId();
33
+      expect(() => {
34
+        // act
35
+        (service as any).registerConverter(duplicateConverter);
36
+      })
37
+      // assert
38
+        .toThrowError(`Converter-ID ${duplicateConverterId} is already registered!`);
39
+    }));
15 40
 });

+ 3
- 3
src/app/native-library-wrapper.service.ts View File

@@ -7,9 +7,9 @@ import * as NativeUtf8 from 'utf8';
7 7
   providedIn: 'root'
8 8
 })
9 9
 export class NativeLibraryWrapperService {
10
-  public utf8: Utf8;
11
-  public quotedPrintable: QuotedPrintable;
12
-  public punycode: Punycode;
10
+  public readonly utf8: Utf8;
11
+  public readonly quotedPrintable: QuotedPrintable;
12
+  public readonly punycode: Punycode;
13 13
 
14 14
   constructor() {
15 15
     this.utf8 = NativeUtf8;

Loading…
Cancel
Save