Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtanko committed Nov 14, 2024
1 parent 376ee5b commit cab59c0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/src/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension NullableExtensions on Object? {
/// Allows performing an action if the object is not null.
///
/// [action] The function to execute if the object is not null.
void run(void Function(Object it) action) {
void runWithAction(void Function(Object it) action) {
if (this != null) {
action(this!);
}
Expand Down
4 changes: 2 additions & 2 deletions test/object_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ void main() {
// ignore: unnecessary_nullable_for_final_variable_declarations
const Object? value = 'World';
String? result;
value.run((it) => result = 'Hello, ${it as String}');
value.runWithAction((it) => result = 'Hello, ${it as String}');
expect(result, 'Hello, World');
});

test('run should not execute action if object is null', () {
const Object? value = null;
String? result = 'Hello';
value.run((it) => result = 'World');
value.runWithAction((it) => result = 'World');
expect(result, 'Hello'); // Result should be unchanged
});

Expand Down
5 changes: 5 additions & 0 deletions test/stream_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ void main() {
expect(actionCalled, isFalse);
});

test('unwrap throws error if stream is null', () async {
const Stream<int?>? nullableStream = null;
expect(() => nullableStream.unwrap().first, throwsA('Stream is null'));
});

test('unwrap throws error if stream contains null value', () async {
final Stream<int?> nullableStream = Stream.value(null);
expect(() => nullableStream.unwrap().first, throwsA('Value is null'));
Expand Down

0 comments on commit cab59c0

Please sign in to comment.