diff --git a/src/app/converter/base64-decoder.spec.ts b/src/app/converter/base64-decoder.spec.ts
index 0133e20..1e144c7 100644
--- a/src/app/converter/base64-decoder.spec.ts
+++ b/src/app/converter/base64-decoder.spec.ts
@@ -1,16 +1,23 @@
import {Base64Decoder} from './base64-decoder';
describe('Base64Decoder', () => {
+ let sut: Base64Decoder;
+
+ beforeEach(() => sut = new Base64Decoder());
+
it('should create an instance', () => {
- expect(new Base64Decoder()).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "base64decode"', () => {
- expect(new Base64Decoder().getId()).toEqual('base64decode');
+ expect(sut.getId()).toEqual('base64decode');
});
+
it('should decode "SGVsbG8sIFdvcmxkIQ==" to "Hello, World!"', () => {
- expect(new Base64Decoder().convert('SGVsbG8sIFdvcmxkIQ==')).toEqual('Hello, World!');
+ expect(sut.convert('SGVsbG8sIFdvcmxkIQ==')).toEqual('Hello, World!');
});
+
it('should raise an exception on invalid input', () => {
- expect(() => new Base64Decoder().convert('foo bar.')).toThrowError('Could not decode base64 string. Maybe corrupt input?');
+ expect(() => sut.convert('foo bar.')).toThrowError('Could not decode base64 string. Maybe corrupt input?');
});
});
diff --git a/src/app/converter/base64-encoder.spec.ts b/src/app/converter/base64-encoder.spec.ts
index 889912e..a8a17aa 100644
--- a/src/app/converter/base64-encoder.spec.ts
+++ b/src/app/converter/base64-encoder.spec.ts
@@ -1,16 +1,23 @@
import {Base64Encoder} from './base64-encoder';
describe('Base64Encoder', () => {
+ let sut: Base64Encoder;
+
+ beforeEach(() => sut = new Base64Encoder());
+
it('should create an instance', () => {
- expect(new Base64Encoder()).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "base64encode"', () => {
- expect(new Base64Encoder().getId()).toEqual('base64encode');
+ expect(sut.getId()).toEqual('base64encode');
});
+
it('should encode "Oh, guete Tag!" to "T2gsIGd1ZXRlIFRhZyE="', () => {
- expect(new Base64Encoder().convert('Oh, guete Tag!')).toEqual('T2gsIGd1ZXRlIFRhZyE=');
+ expect(sut.convert('Oh, guete Tag!')).toEqual('T2gsIGd1ZXRlIFRhZyE=');
});
+
it('should raise an exception on invalid input', () => {
- expect(() => new Base64Encoder().convert('€')).toThrowError(/Looks like you've got a character outside of the Latin1 range there./);
+ expect(() => sut.convert('€')).toThrowError(/Looks like you've got a character outside of the Latin1 range there./);
});
});
diff --git a/src/app/converter/bin-to-dec-converter.spec.ts b/src/app/converter/bin-to-dec-converter.spec.ts
index a67bbb0..7629672 100644
--- a/src/app/converter/bin-to-dec-converter.spec.ts
+++ b/src/app/converter/bin-to-dec-converter.spec.ts
@@ -1,16 +1,23 @@
import {BinToDecConverter} from './bin-to-dec-converter';
describe('BinToDecConverter', () => {
+ let sut: BinToDecConverter;
+
+ beforeEach(() => sut = new BinToDecConverter());
+
it('should create an instance', () => {
- expect(new BinToDecConverter()).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "bintodec"', () => {
- expect(new BinToDecConverter().getId()).toEqual('bintodec');
+ expect(sut.getId()).toEqual('bintodec');
});
+
it('should convert "11011" to "27"', () => {
- expect(new BinToDecConverter().convert('11011')).toEqual('27');
+ expect(sut.convert('11011')).toEqual('27');
});
+
it('should raise an exception on invalid input', () => {
- expect(() => new BinToDecConverter().convert('1foo bar')).toThrowError('The input seems not to be a valid binary number.');
+ expect(() => sut.convert('1foo bar')).toThrowError('The input seems not to be a valid binary number.');
});
});
diff --git a/src/app/converter/dec-to-bin-converter.spec.ts b/src/app/converter/dec-to-bin-converter.spec.ts
index e32fa18..9022275 100644
--- a/src/app/converter/dec-to-bin-converter.spec.ts
+++ b/src/app/converter/dec-to-bin-converter.spec.ts
@@ -1,16 +1,23 @@
import {DecToBinConverter} from './dec-to-bin-converter';
describe('DecToBinConverter', () => {
+ let sut: DecToBinConverter;
+
+ beforeEach(() => sut = new DecToBinConverter());
+
it('should create an instance', () => {
- expect(new DecToBinConverter()).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "dectobin"', () => {
- expect(new DecToBinConverter().getId()).toEqual('dectobin');
+ expect(sut.getId()).toEqual('dectobin');
});
+
it('should convert "22" to "10110"', () => {
- expect(new DecToBinConverter().convert('22')).toEqual('10110');
+ expect(sut.convert('22')).toEqual('10110');
});
+
it('should raise an exception on invalid input', () => {
- expect(() => new DecToBinConverter().convert('foo bar')).toThrowError('The input seems not to be a valid integer.');
+ expect(() => sut.convert('foo bar')).toThrowError('The input seems not to be a valid integer.');
});
});
diff --git a/src/app/converter/dec-to-hex-converter.spec.ts b/src/app/converter/dec-to-hex-converter.spec.ts
index 152612f..90e344b 100644
--- a/src/app/converter/dec-to-hex-converter.spec.ts
+++ b/src/app/converter/dec-to-hex-converter.spec.ts
@@ -1,16 +1,23 @@
import {DecToHexConverter} from './dec-to-hex-converter';
describe('DecToHexConverter', () => {
+ let sut: DecToHexConverter;
+
+ beforeEach(() => sut = new DecToHexConverter());
+
it('should create an instance', () => {
- expect(new DecToHexConverter()).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "dectohex"', () => {
- expect(new DecToHexConverter().getId()).toEqual('dectohex');
+ expect(sut.getId()).toEqual('dectohex');
});
+
it('should convert "22" to "16"', () => {
- expect(new DecToHexConverter().convert('22')).toEqual('16');
+ expect(sut.convert('22')).toEqual('16');
});
+
it('should raise an exception on invalid input', () => {
- expect(() => new DecToHexConverter().convert('foo bar')).toThrowError('The input seems not to be a valid integer.');
+ expect(() => sut.convert('foo bar')).toThrowError('The input seems not to be a valid integer.');
});
});
diff --git a/src/app/converter/hex-to-dec-converter.spec.ts b/src/app/converter/hex-to-dec-converter.spec.ts
index f01c833..4fc3f15 100644
--- a/src/app/converter/hex-to-dec-converter.spec.ts
+++ b/src/app/converter/hex-to-dec-converter.spec.ts
@@ -1,16 +1,23 @@
import {HexToDecConverter} from './hex-to-dec-converter';
describe('HexToDecConverter', () => {
+ let sut: HexToDecConverter;
+
+ beforeEach(() => sut = new HexToDecConverter());
+
it('should create an instance', () => {
- expect(new HexToDecConverter()).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "hextodec"', () => {
- expect(new HexToDecConverter().getId()).toEqual('hextodec');
+ expect(sut.getId()).toEqual('hextodec');
});
+
it('should convert "ab" to "171"', () => {
- expect(new HexToDecConverter().convert('ab')).toEqual('171');
+ expect(sut.convert('ab')).toEqual('171');
});
+
it('should raise an exception on invalid input', () => {
- expect(() => new HexToDecConverter().convert('foo bar')).toThrowError('The input seems not to be a valid hexadecimal number.');
+ expect(() => sut.convert('foo bar')).toThrowError('The input seems not to be a valid hexadecimal number.');
});
});
diff --git a/src/app/converter/htmlentities-decoder.spec.ts b/src/app/converter/htmlentities-decoder.spec.ts
index 08136ea..9130639 100644
--- a/src/app/converter/htmlentities-decoder.spec.ts
+++ b/src/app/converter/htmlentities-decoder.spec.ts
@@ -1,14 +1,20 @@
import {HTMLEntitiesDecoder} from './htmlentities-decoder';
describe('HTMLEntitiesDecoder', () => {
+ let sut: HTMLEntitiesDecoder;
+
+ beforeEach(() => sut = new HTMLEntitiesDecoder());
+
it('should create an instance', () => {
- expect(new HTMLEntitiesDecoder()).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "decodehtmlentities"', () => {
- expect(new HTMLEntitiesDecoder().getId()).toEqual('decodehtmlentities');
+ expect(sut.getId()).toEqual('decodehtmlentities');
});
+
it('should decode "<span>"Hi" & "Lo"</span>" to ""Hi" & "Lo""', () => {
- expect(new HTMLEntitiesDecoder().convert('<span>"Hi" & "Lo"</span>'))
+ expect(sut.convert('<span>"Hi" & "Lo"</span>'))
.toEqual('"Hi" & "Lo"');
});
});
diff --git a/src/app/converter/htmlentities-encoder.spec.ts b/src/app/converter/htmlentities-encoder.spec.ts
index 5c6aa09..94319fa 100644
--- a/src/app/converter/htmlentities-encoder.spec.ts
+++ b/src/app/converter/htmlentities-encoder.spec.ts
@@ -1,14 +1,20 @@
import {HTMLEntitiesEncoder} from './htmlentities-encoder';
describe('HTMLEntitiesEncoder', () => {
+ let sut: HTMLEntitiesEncoder;
+
+ beforeEach(() => sut = new HTMLEntitiesEncoder());
+
it('should create an instance', () => {
- expect(new HTMLEntitiesEncoder()).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "encodehtmlentities"', () => {
- expect(new HTMLEntitiesEncoder().getId()).toEqual('encodehtmlentities');
+ expect(sut.getId()).toEqual('encodehtmlentities');
});
+
it('should encode ""Hi" & "Lo"" to "<span>"Hi" & "Lo"</span>"', () => {
- expect(new HTMLEntitiesEncoder().convert('"Hi" & "Lo"'))
+ expect(sut.convert('"Hi" & "Lo"'))
.toEqual('<span>"Hi" & "Lo"</span>');
});
});
diff --git a/src/app/converter/punycode-decoder.spec.ts b/src/app/converter/punycode-decoder.spec.ts
index 12c21e9..ab3e8d3 100644
--- a/src/app/converter/punycode-decoder.spec.ts
+++ b/src/app/converter/punycode-decoder.spec.ts
@@ -4,23 +4,29 @@ import createSpyObj = jasmine.createSpyObj;
import Spy = jasmine.Spy;
describe('PunycodeDecoder', () => {
+ let sut: PunycodeDecoder;
let nativeWrapperSpy: Partial;
let decodeSpy: Spy;
+
beforeEach(() => {
nativeWrapperSpy = {punycode: createSpyObj(['decode'])};
decodeSpy = nativeWrapperSpy.punycode.decode as Spy;
+ sut = new PunycodeDecoder((nativeWrapperSpy as NativeLibraryWrapperService));
});
+
it('should create an instance', () => {
- expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "decodepunycode"', () => {
- expect(new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('decodepunycode');
+ expect(sut.getId()).toEqual('decodepunycode');
});
+
it('should call through to the native punycode decoder', () => {
const testInput = 'My input';
const expectedOutput = 'It worked';
decodeSpy.and.returnValue(expectedOutput);
- const result: string = new PunycodeDecoder(nativeWrapperSpy as NativeLibraryWrapperService).convert(testInput);
+ const result: string = sut.convert(testInput);
expect(result).toEqual(expectedOutput);
expect(decodeSpy).toHaveBeenCalledWith(testInput);
});
diff --git a/src/app/converter/punycode-encoder.spec.ts b/src/app/converter/punycode-encoder.spec.ts
index 9da3d8a..8c872b0 100644
--- a/src/app/converter/punycode-encoder.spec.ts
+++ b/src/app/converter/punycode-encoder.spec.ts
@@ -4,23 +4,29 @@ import createSpyObj = jasmine.createSpyObj;
import Spy = jasmine.Spy;
describe('PunycodeEncoder', () => {
+ let sut: PunycodeEncoder;
let nativeWrapperSpy: Partial;
let encodeSpy: Spy;
+
beforeEach(() => {
nativeWrapperSpy = {punycode: createSpyObj(['encode'])};
encodeSpy = nativeWrapperSpy.punycode.encode as Spy;
+ sut = new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService);
});
+
it('should create an instance', () => {
- expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService)).toBeTruthy();
+ expect(sut).toBeTruthy();
});
+
it('should have the id "encodepunycode"', () => {
- expect(new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService).getId()).toEqual('encodepunycode');
+ expect(sut.getId()).toEqual('encodepunycode');
});
+
it('should call through to the native punycode encoder', () => {
const testInput = 'My input';
const expectedOutput = 'It worked';
encodeSpy.and.returnValue(expectedOutput);
- const result: string = new PunycodeEncoder(nativeWrapperSpy as NativeLibraryWrapperService).convert(testInput);
+ const result: string = sut.convert(testInput);
expect(result).toEqual(expectedOutput);
expect(encodeSpy).toHaveBeenCalledWith(testInput);
});