Skip to content

Commit

Permalink
Replace "!is" with "is!"
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 authored and hoangdat committed Sep 13, 2024
1 parent 75719ed commit 3c5b0d9
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/features/base/reloadable/reloadable_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ abstract class ReloadableController extends BaseController {
}

void _handleGetSessionFailure(GetSessionFailure failure) {
if (failure.exception !is BadCredentialsException) {
if (failure.exception is! BadCredentialsException) {
toastManager.showMessageFailure(failure);
}
clearDataAndGoToLoginPage();
Expand Down
88 changes: 88 additions & 0 deletions test/main/utils/type_operator_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';

bool isNotBadCredentialsExceptionUseIsNotOperator(dynamic exception) {
return exception is! BadCredentialsException;
}

bool isBadCredentialsExceptionUseIsOperator(dynamic exception) {
return exception is BadCredentialsException;
}

bool isBadCredentialsExceptionUseNotIsOperator(dynamic exception) {
return exception !is BadCredentialsException;
}

void main() {
group('is! operator unit test', () {
test('should return true when exception is not a BadCredentialsException', () {
// Arrange
const connectionError = ConnectionError();

// Act
final result = isNotBadCredentialsExceptionUseIsNotOperator(connectionError);

// Assert
expect(result, true);
});

test('should return false when exception is a BadCredentialsException', () {
// Arrange
const badCredentialsException = BadCredentialsException();

// Act
final result = isNotBadCredentialsExceptionUseIsNotOperator(badCredentialsException);

// Assert
expect(result, false);
});
});

group('is operator unit test', () {
test('should return true when exception is a BadCredentialsException', () {
// Arrange
const badCredentialsException = BadCredentialsException();

// Act
final result = isBadCredentialsExceptionUseIsOperator(badCredentialsException);

// Assert
expect(result, true);
});

test('should return false when exception is not a BadCredentialsException', () {
// Arrange
const connectionError = ConnectionError();

// Act
final result = isBadCredentialsExceptionUseIsOperator(connectionError);

// Assert
expect(result, false);
});
});

group('!is operator unit test', () {
test('should return true when exception is a BadCredentialsException', () {
// Arrange
const badCredentialsException = BadCredentialsException();

// Act
final result = isBadCredentialsExceptionUseNotIsOperator(badCredentialsException);

// Assert
expect(result, true);
});

test('should return false when exception is not a BadCredentialsException', () {
// Arrange
const connectionError = ConnectionError();

// Act
final result = isBadCredentialsExceptionUseNotIsOperator(connectionError);

// Assert
expect(result, false);
});
});
}

0 comments on commit 3c5b0d9

Please sign in to comment.