1 2// Copyright (C) 2018 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15 16import {Registry} from './registry'; 17 18interface Registrant { 19 kind: string; 20 n: number; 21} 22 23test('registry returns correct registrant', () => { 24 const registry = new Registry<Registrant>(); 25 26 const a: Registrant = {kind: 'a', n: 1}; 27 const b: Registrant = {kind: 'b', n: 2}; 28 registry.register(a); 29 registry.register(b); 30 31 expect(registry.get('a')).toBe(a); 32 expect(registry.get('b')).toBe(b); 33}); 34 35test('registry throws error on kind collision', () => { 36 const registry = new Registry<Registrant>(); 37 38 const a1: Registrant = {kind: 'a', n: 1}; 39 const a2: Registrant = {kind: 'a', n: 2}; 40 41 registry.register(a1); 42 expect(() => registry.register(a2)).toThrow(); 43}); 44 45test('registry throws error on non-existent track', () => { 46 const registry = new Registry<Registrant>(); 47 expect(() => registry.get('foo')).toThrow(); 48}); 49