Skip to content

Commit

Permalink
Expect exception for unsupported feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rekire committed Mar 16, 2024
1 parent 28a2bde commit bcb533d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 12 deletions.
71 changes: 71 additions & 0 deletions autologin_linux/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
include: package:very_good_analysis/analysis_options.5.1.0.yaml

linter:
rules:
prefer_single_quotes: true
always_declare_return_types: true
always_put_control_body_on_new_line: true
always_use_package_imports: true
annotate_overrides: true
avoid_bool_literals_in_conditional_expressions: true
avoid_multiple_declarations_per_line: true
avoid_positional_boolean_parameters: true
avoid_redundant_argument_values: true
avoid_unnecessary_containers: true
curly_braces_in_flow_control_structures: true
do_not_use_environment: true
lines_longer_than_80_chars: false
require_trailing_commas: true
flutter_style_todos: true
public_member_api_docs: false
cascade_invocations: false
sort_constructors_first: false
eol_at_end_of_file: false
join_return_with_assignment: false
use_if_null_to_convert_nulls_to_bools: false
use_setters_to_change_properties: false

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
analyzer:
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "**/firebase_options.dart"
- "**/locale_keys.dart"
- "**/*.mocks.dart"
errors:
invalid_annotation_target: ignore

# dart code metrics Basic configuration
plugins:
- dart_code_metrics

dart_code_metrics:
anti-patterns:
- long-method
- long-parameter-list
metrics:
cyclomatic-complexity: 20
maximum-nesting-level: 5
number-of-parameters: 6
source-lines-of-code: 100
metrics-exclude:
- test/**
- integration_test/**
rules-exclude:
- test/**
- integration_test/**
rules:
- no-boolean-literal-compare
- no-empty-block
- prefer-trailing-comma
- no-equal-then-else
- prefer-first
- prefer-last
- prefer-match-file-name
- always-remove-listener
- avoid-unnecessary-setstate
- avoid-wrapping-in-padding
- prefer-single-widget-per-file:
ignore-private-widgets: true
- avoid-global-state
20 changes: 8 additions & 12 deletions autologin_linux/test/autologin_linux_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void main() {
late List<MethodCall> log;
const expectedCompatibilities = Compatibilities(isPlatformSupported: true);
const expectedCredentials = Credential(username: 'foo', password: 'bar');
const expectedToken = 'Example-Token';

setUp(() async {
autologin = AutologinLinux();
Expand All @@ -28,6 +29,9 @@ void main() {
return jsonEncode(expectedCredentials.toJson());
case 'saveCredentials':
return 'true';
case 'requestLoginToken':
case 'saveLoginToken':
throw Error();
default:
return null;
}
Expand Down Expand Up @@ -67,21 +71,13 @@ void main() {
});

test('requestLoginToken returns nothing', () async {
final token = await autologin.requestLoginToken();
expect(
log,
<Matcher>[isMethodCall('requestLoginToken', arguments: null)],
);
expect(token, equals(null));
expect(log, <Matcher>[]);
expect(() async => autologin.requestLoginToken(), throwsA(const TypeMatcher<PlatformException>()));
});

test('saveLoginToken returns expected value', () async {
final report = await autologin.saveLoginToken(expectedToken);
expect(
log,
<Matcher>[isMethodCall('saveLoginToken', arguments: expectedToken)],
);
expect(report, equals(false));
expect(log, <Matcher>[]);
expect(() async => autologin.saveLoginToken(expectedToken), throwsA(const TypeMatcher<PlatformException>()));
});
});
}

0 comments on commit bcb533d

Please sign in to comment.