|
| 1 | +// Copyright 2023 Contributors to the Eclipse Foundation. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | +// |
| 5 | +// SPDX-License-Identifier: BSD-3-Clause |
| 6 | + |
| 7 | +import 'package:dart_wot/dart_wot.dart'; |
| 8 | +import 'package:test/test.dart'; |
| 9 | + |
| 10 | +const testUriScheme = 'test'; |
| 11 | + |
| 12 | +class MockedProtocolClientFactory implements ProtocolClientFactory { |
| 13 | + @override |
| 14 | + ProtocolClient createClient() { |
| 15 | + throw UnimplementedError('Instantiating a client is not supported yet.'); |
| 16 | + } |
| 17 | + |
| 18 | + @override |
| 19 | + bool destroy() { |
| 20 | + return true; |
| 21 | + } |
| 22 | + |
| 23 | + @override |
| 24 | + bool init() { |
| 25 | + return true; |
| 26 | + } |
| 27 | + |
| 28 | + @override |
| 29 | + Set<String> get schemes => {testUriScheme}; |
| 30 | +} |
| 31 | + |
| 32 | +void main() { |
| 33 | + group('Servient Tests', () { |
| 34 | + test('Should accept a ProtocolClientFactory list as constructor argument', |
| 35 | + () { |
| 36 | + final servient = Servient( |
| 37 | + clientFactories: [ |
| 38 | + MockedProtocolClientFactory(), |
| 39 | + ], |
| 40 | + ); |
| 41 | + |
| 42 | + expect(servient.clientSchemes, [testUriScheme]); |
| 43 | + expect(servient.hasClientFor(testUriScheme), true); |
| 44 | + }); |
| 45 | + |
| 46 | + test( |
| 47 | + 'Should allow for adding and removing a ProtocolClientFactory at runtime', |
| 48 | + () { |
| 49 | + final servient = Servient() |
| 50 | + ..addClientFactory(MockedProtocolClientFactory()); |
| 51 | + |
| 52 | + expect(servient.hasClientFor(testUriScheme), true); |
| 53 | + |
| 54 | + servient.removeClientFactory(testUriScheme); |
| 55 | + |
| 56 | + expect(servient.hasClientFor(testUriScheme), false); |
| 57 | + expect(servient.clientSchemes.length, 0); |
| 58 | + }, |
| 59 | + ); |
| 60 | + }); |
| 61 | +} |
0 commit comments