Skip to content

Commit

Permalink
test(servient): add tests for handling ProtocolClientFactories
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Dec 19, 2023
1 parent 0facb78 commit 568bb89
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/core/servient_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2023 Contributors to the Eclipse Foundation. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// SPDX-License-Identifier: BSD-3-Clause

import 'package:dart_wot/dart_wot.dart';
import 'package:test/test.dart';

const testUriScheme = 'test';

class MockedProtocolClientFactory implements ProtocolClientFactory {
@override
ProtocolClient createClient() {
throw UnimplementedError('Instantiating a client is not supported yet.');
}

@override
bool destroy() {
return true;
}

@override
bool init() {
return true;
}

@override
Set<String> get schemes => {testUriScheme};
}

void main() {
group('Servient Tests', () {
test('Should accept a ProtocolClientFactory list as constructor argument',
() {
final servient = Servient(
clientFactories: [
MockedProtocolClientFactory(),
],
);

expect(servient.clientSchemes, [testUriScheme]);
expect(servient.hasClientFor(testUriScheme), true);
});

test(
'Should allow for adding and removing a ProtocolClientFactory at runtime',
() {
final servient = Servient()
..addClientFactory(MockedProtocolClientFactory());

expect(servient.hasClientFor(testUriScheme), true);

servient.removeClientFactory(testUriScheme);

expect(servient.hasClientFor(testUriScheme), false);
expect(servient.clientSchemes.length, 0);
},
);
});
}

0 comments on commit 568bb89

Please sign in to comment.