Skip to content

Commit

Permalink
test(binding_coap): add server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Mar 21, 2022
1 parent 3819b8b commit f3dba12
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/binding_coap_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022 The NAMIB Project Developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// SPDX-License-Identifier: MIT OR Apache-2.0

import 'package:dart_wot/dart_wot.dart';
import 'package:mockito/annotations.dart';
import 'package:test/test.dart';
import 'binding_coap_test.mocks.dart';

@GenerateMocks([ExposedThing])
void main() {
group('CoAP Binding Tests', () {
setUp(() {
// Additional setup goes here.
});

test("Server tests", () {
final defaultServer = CoapServer(null);

expect(defaultServer.port, 5683);
expect(defaultServer.scheme, "coap");

expect(() async => await defaultServer.start({}),
throwsA(TypeMatcher<UnimplementedError>()));
expect(() async => await defaultServer.stop(),
throwsA(TypeMatcher<UnimplementedError>()));
expect(() async => await defaultServer.expose(MockExposedThing()),
throwsA(TypeMatcher<UnimplementedError>()));

final customServer = CoapServer(CoapConfig(port: 9001, blocksize: 64));

expect(customServer.port, 9001);
expect(customServer.preferredBlockSize, 64);
});
});
}
99 changes: 99 additions & 0 deletions test/binding_coap_test.mocks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Mocks generated by Mockito 5.1.0 from annotations
// in dart_wot/test/binding_coap/binding_coap_test.dart.
// Do not manually edit this file.

import 'dart:async' as _i4;

import 'package:dart_wot/src/definitions/thing_description.dart' as _i2;
import 'package:dart_wot/src/scripting_api/exposed_thing.dart' as _i3;
import 'package:mockito/mockito.dart' as _i1;

// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types

class _FakeThingDescription_0 extends _i1.Fake implements _i2.ThingDescription {
}

/// A class which mocks [ExposedThing].
///
/// See the documentation for Mockito's code generation for more information.
class MockExposedThing extends _i1.Mock implements _i3.ExposedThing {
MockExposedThing() {
_i1.throwOnMissingStub(this);
}

@override
_i2.ThingDescription get thingDescription =>
(super.noSuchMethod(Invocation.getter(#thingDescription),
returnValue: _FakeThingDescription_0()) as _i2.ThingDescription);
@override
_i4.Future<void> expose() =>
(super.noSuchMethod(Invocation.method(#expose, []),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i4.Future<void>);
@override
_i4.Future<void> destroy() =>
(super.noSuchMethod(Invocation.method(#destroy, []),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i4.Future<void>);
@override
void setPropertyReadHandler(String? name, _i3.PropertyReadHandler? handler) =>
super.noSuchMethod(
Invocation.method(#setPropertyReadHandler, [name, handler]),
returnValueForMissingStub: null);
@override
void setPropertyWriteHandler(
String? name, _i3.PropertyWriteHandler? handler) =>
super.noSuchMethod(
Invocation.method(#setPropertyWriteHandler, [name, handler]),
returnValueForMissingStub: null);
@override
void setPropertyObserveHandler(
String? name, _i3.PropertyReadHandler? handler) =>
super.noSuchMethod(
Invocation.method(#setPropertyObserveHandler, [name, handler]),
returnValueForMissingStub: null);
@override
void setPropertyUnobserveHandler(
String? name, _i3.PropertyReadHandler? handler) =>
super.noSuchMethod(
Invocation.method(#setPropertyUnobserveHandler, [name, handler]),
returnValueForMissingStub: null);
@override
_i4.Future<void> emitPropertyChange(String? name) =>
(super.noSuchMethod(Invocation.method(#emitPropertyChange, [name]),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i4.Future<void>);
@override
void setActionHandler(String? name, _i3.ActionHandler? handler) =>
super.noSuchMethod(Invocation.method(#setActionHandler, [name, handler]),
returnValueForMissingStub: null);
@override
void setEventSubscribeHandler(
String? name, _i3.EventSubscriptionHandler? handler) =>
super.noSuchMethod(
Invocation.method(#setEventSubscribeHandler, [name, handler]),
returnValueForMissingStub: null);
@override
void setEventUnsubscribeHandler(
String? name, _i3.EventSubscriptionHandler? handler) =>
super.noSuchMethod(
Invocation.method(#setEventUnsubscribeHandler, [name, handler]),
returnValueForMissingStub: null);
@override
void setEventHandler(String? name, _i3.EventListenerHandler? handler) =>
super.noSuchMethod(Invocation.method(#setEventHandler, [name, handler]),
returnValueForMissingStub: null);
@override
_i4.Future<void> emitEvent(String? name, Object? data) =>
(super.noSuchMethod(Invocation.method(#emitEvent, [name, data]),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i4.Future<void>);
}

0 comments on commit f3dba12

Please sign in to comment.