Skip to content

Commit

Permalink
test(icon_generator): added tests for IconGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
RatakondalaArun committed Jul 10, 2022
1 parent 12da70f commit 3e2578e
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/abs/icon_generator_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'package:flutter_launcher_icons/abs/icon_generator.dart';
import 'package:flutter_launcher_icons/flutter_launcher_icons_config.dart';
import 'package:flutter_launcher_icons/logger.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

import 'icon_generator_test.mocks.dart';

@GenerateMocks([FlutterLauncherIconsConfig, IconGenerator])
void main() {
group('#generateIconsFor', () {
late String prefixPath;
late FLILogger logger;
late IconGenerator mockGenerator;
late FlutterLauncherIconsConfig mockFLIConfig;
setUp(() async {
prefixPath = path.join(d.sandbox, 'fli_test');
mockFLIConfig = MockFlutterLauncherIconsConfig();
logger = FLILogger(false);
mockGenerator = MockIconGenerator();
when(mockGenerator.platformName).thenReturn('Mock');
when(mockGenerator.context).thenReturn(IconGeneratorContext(
config: mockFLIConfig,
prefixPath: prefixPath,
logger: logger,
));
});
test('should execute createIcons() when validateRequiremnts() returns true', () {
when(mockGenerator.validateRequirments()).thenReturn(true);
generateIconsFor(
config: mockFLIConfig,
flavor: null,
prefixPath: prefixPath,
logger: logger,
platforms: (context) => [mockGenerator],
);
verify(mockGenerator.validateRequirments()).called(equals(1));
verify(mockGenerator.createIcons()).called(equals(1));
});

test('should not execute createIcons() when validateRequiremnts() returns false', () {
when(mockGenerator.validateRequirments()).thenReturn(false);
generateIconsFor(
config: mockFLIConfig,
flavor: null,
prefixPath: prefixPath,
logger: logger,
platforms: (context) => [mockGenerator],
);
verify(mockGenerator.validateRequirments()).called(equals(1));
verifyNever(mockGenerator.createIcons());
});

test('should skip platform if any exception occured', () {
when(mockGenerator.validateRequirments()).thenReturn(true);
when(mockGenerator.createIcons()).thenThrow(Exception('should-skip-platform'));
generateIconsFor(
config: mockFLIConfig,
flavor: null,
prefixPath: prefixPath,
logger: logger,
platforms: (context) => [mockGenerator],
);
verify(mockGenerator.validateRequirments()).called(equals(1));
verify(mockGenerator.createIcons()).called(equals(1));
expect(() => mockGenerator.createIcons(), throwsException);
});
});
}
61 changes: 61 additions & 0 deletions test/abs/icon_generator_test.mocks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Mocks generated by Mockito 5.2.0 from annotations
// in flutter_launcher_icons/test/abs/icon_generator_test.dart.
// Do not manually edit this file.

import 'package:flutter_launcher_icons/abs/icon_generator.dart' as _i2;
import 'package:flutter_launcher_icons/flutter_launcher_icons_config.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 _FakeIconGeneratorContext_0 extends _i1.Fake
implements _i2.IconGeneratorContext {}

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

@override
Map<String, dynamic> toJson() =>
(super.noSuchMethod(Invocation.method(#toJson, []),
returnValue: <String, dynamic>{}) as Map<String, dynamic>);
}

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

@override
_i2.IconGeneratorContext get context => (super.noSuchMethod(
Invocation.getter(#context),
returnValue: _FakeIconGeneratorContext_0()) as _i2.IconGeneratorContext);
@override
String get platformName =>
(super.noSuchMethod(Invocation.getter(#platformName), returnValue: '')
as String);
@override
void createIcons() => super.noSuchMethod(Invocation.method(#createIcons, []),
returnValueForMissingStub: null);
@override
bool validateRequirments() =>
(super.noSuchMethod(Invocation.method(#validateRequirments, []),
returnValue: false) as bool);
}

0 comments on commit 3e2578e

Please sign in to comment.