Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
aa9b2d91
Unverified
Commit
aa9b2d91
authored
May 14, 2021
by
Jonah Williams
Committed by
GitHub
May 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mocks from application_package_test (#82568)
parent
6a75f8e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
38 deletions
+45
-38
application_package_test.dart
...er_tools/test/general.shard/application_package_test.dart
+45
-38
No files found.
packages/flutter_tools/test/general.shard/application_package_test.dart
View file @
aa9b2d91
...
...
@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/application_package.dart';
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/os.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/base/user_messages.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/cache.dart'
;
...
...
@@ -21,23 +20,15 @@ import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import
'package:flutter_tools/src/ios/application_package.dart'
;
import
'package:flutter_tools/src/ios/plist_parser.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../src/common.dart'
;
import
'../src/context.dart'
;
import
'../src/fakes.dart'
;
FakePlatform
_kNoColorTerminalPlatform
(
)
=>
FakePlatform
(
stdoutSupportsAnsi:
false
);
final
Map
<
Type
,
Generator
>
noColorTerminalOverride
=
<
Type
,
Generator
>{
Platform:
_kNoColorTerminalPlatform
,
};
class
MockitoAndroidSdk
extends
Mock
implements
AndroidSdk
{}
class
MockitoAndroidSdkVersion
extends
Mock
implements
AndroidSdkVersion
{}
void
main
(
)
{
group
(
'Apk with partial Android SDK works'
,
()
{
AndroidSdk
sdk
;
Fake
AndroidSdk
sdk
;
FakeProcessManager
fakeProcessManager
;
MemoryFileSystem
fs
;
Cache
cache
;
...
...
@@ -50,14 +41,14 @@ void main() {
};
setUp
(()
async
{
sdk
=
Mockito
AndroidSdk
();
sdk
=
Fake
AndroidSdk
();
fakeProcessManager
=
FakeProcessManager
.
empty
();
fs
=
MemoryFileSystem
.
test
();
cache
=
Cache
.
test
(
processManager:
FakeProcessManager
.
any
(),
);
Cache
.
flutterRoot
=
'../..'
;
when
(
sdk
.
licensesAvailable
).
thenReturn
(
true
)
;
sdk
.
licensesAvailable
=
true
;
final
FlutterProject
project
=
FlutterProject
.
fromDirectoryTest
(
fs
.
currentDirectory
);
fs
.
file
(
project
.
android
.
hostAppGradleRoot
.
childFile
(
globals
.
platform
.
isWindows
?
'gradlew.bat'
:
'gradlew'
,
...
...
@@ -67,11 +58,11 @@ void main() {
testUsingContext
(
'Licenses not available, platform and buildtools available, apk exists'
,
()
async
{
const
String
aaptPath
=
'aaptPath'
;
final
File
apkFile
=
globals
.
fs
.
file
(
'app.apk'
);
final
AndroidSdkVersion
sdkVersion
=
Mockito
AndroidSdkVersion
();
when
(
sdkVersion
.
aaptPath
).
thenReturn
(
aaptPath
)
;
when
(
sdk
.
latestVersion
).
thenReturn
(
sdkVersion
)
;
when
(
sdk
.
platformToolsAvailable
).
thenReturn
(
true
)
;
when
(
sdk
.
licensesAvailable
).
thenReturn
(
false
)
;
final
FakeAndroidSdkVersion
sdkVersion
=
Fake
AndroidSdkVersion
();
sdkVersion
.
aaptPath
=
aaptPath
;
sdk
.
latestVersion
=
sdkVersion
;
sdk
.
platformToolsAvailable
=
true
;
sdk
.
licensesAvailable
=
false
;
fakeProcessManager
.
addCommand
(
FakeCommand
(
...
...
@@ -96,7 +87,7 @@ void main() {
},
overrides:
overrides
);
testUsingContext
(
'Licenses available, build tools not, apk exists'
,
()
async
{
when
(
sdk
.
latestVersion
).
thenReturn
(
null
)
;
sdk
.
latestVersion
=
null
;
final
FlutterProject
project
=
FlutterProject
.
fromDirectoryTest
(
fs
.
currentDirectory
);
project
.
android
.
hostAppGradleRoot
.
childFile
(
'gradle.properties'
)
...
...
@@ -118,8 +109,8 @@ void main() {
},
overrides:
overrides
);
testUsingContext
(
'Licenses available, build tools available, does not call gradle dependencies'
,
()
async
{
final
AndroidSdkVersion
sdkVersion
=
Mockito
AndroidSdkVersion
();
when
(
sdk
.
latestVersion
).
thenReturn
(
sdkVersion
)
;
final
AndroidSdkVersion
sdkVersion
=
Fake
AndroidSdkVersion
();
sdk
.
latestVersion
=
sdkVersion
;
await
ApplicationPackageFactory
.
instance
.
getPackageForPlatform
(
TargetPlatform
.
android_arm
,
...
...
@@ -129,8 +120,8 @@ void main() {
},
overrides:
overrides
);
testWithoutContext
(
'returns null when failed to extract manifest'
,
()
async
{
final
AndroidSdkVersion
sdkVersion
=
Mockito
AndroidSdkVersion
();
when
(
sdk
.
latestVersion
).
thenReturn
(
sdkVersion
)
;
final
AndroidSdkVersion
sdkVersion
=
Fake
AndroidSdkVersion
();
sdk
.
latestVersion
=
sdkVersion
;
final
AndroidApk
androidApk
=
AndroidApk
.
fromApk
(
null
,
processManager:
fakeProcessManager
,
...
...
@@ -242,19 +233,18 @@ void main() {
});
group
(
'PrebuiltIOSApp'
,
()
{
Mock
OperatingSystemUtils
os
;
Fake
OperatingSystemUtils
os
;
FakePlistParser
testPlistParser
;
final
Map
<
Type
,
Generator
>
overrides
=
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
PlistParser:
()
=>
testPlistParser
,
Platform:
_kNoColorTerminalPlatform
,
OperatingSystemUtils:
()
=>
os
,
};
setUp
(()
{
os
=
Mock
OperatingSystemUtils
();
os
=
Fake
OperatingSystemUtils
();
testPlistParser
=
FakePlistParser
();
});
...
...
@@ -312,7 +302,6 @@ void main() {
testUsingContext
(
'Bad ipa zip-file, no payload dir'
,
()
{
globals
.
fs
.
file
(
'app.ipa'
).
createSync
();
when
(
os
.
unzip
(
globals
.
fs
.
file
(
'app.ipa'
),
any
)).
thenAnswer
((
Invocation
_
)
{
});
final
PrebuiltIOSApp
iosApp
=
IOSApp
.
fromPrebuiltApp
(
globals
.
fs
.
file
(
'app.ipa'
))
as
PrebuiltIOSApp
;
expect
(
iosApp
,
isNull
);
expect
(
...
...
@@ -323,19 +312,17 @@ void main() {
testUsingContext
(
'Bad ipa zip-file, two app bundles'
,
()
{
globals
.
fs
.
file
(
'app.ipa'
).
createSync
();
when
(
os
.
unzip
(
any
,
any
)).
thenAnswer
((
Invocation
invocation
)
{
final
File
zipFile
=
invocation
.
positionalArguments
[
0
]
as
File
;
os
.
onUnzip
=
(
File
zipFile
,
Directory
targetDirectory
)
{
if
(
zipFile
.
path
!=
'app.ipa'
)
{
return
;
}
final
Directory
targetDirectory
=
invocation
.
positionalArguments
[
1
]
as
Directory
;
final
String
bundlePath1
=
globals
.
fs
.
path
.
join
(
targetDirectory
.
path
,
'Payload'
,
'bundle1.app'
);
final
String
bundlePath2
=
globals
.
fs
.
path
.
join
(
targetDirectory
.
path
,
'Payload'
,
'bundle2.app'
);
globals
.
fs
.
directory
(
bundlePath1
).
createSync
(
recursive:
true
);
globals
.
fs
.
directory
(
bundlePath2
).
createSync
(
recursive:
true
);
}
)
;
};
final
PrebuiltIOSApp
iosApp
=
IOSApp
.
fromPrebuiltApp
(
globals
.
fs
.
file
(
'app.ipa'
))
as
PrebuiltIOSApp
;
expect
(
iosApp
,
isNull
);
expect
(
testLogger
.
errorText
,
...
...
@@ -344,12 +331,10 @@ void main() {
testUsingContext
(
'Success with ipa'
,
()
{
globals
.
fs
.
file
(
'app.ipa'
).
createSync
();
when
(
os
.
unzip
(
any
,
any
)).
thenAnswer
((
Invocation
invocation
)
{
final
File
zipFile
=
invocation
.
positionalArguments
[
0
]
as
File
;
os
.
onUnzip
=
(
File
zipFile
,
Directory
targetDirectory
)
{
if
(
zipFile
.
path
!=
'app.ipa'
)
{
return
;
}
final
Directory
targetDirectory
=
invocation
.
positionalArguments
[
1
]
as
Directory
;
final
Directory
bundleAppDir
=
globals
.
fs
.
directory
(
globals
.
fs
.
path
.
join
(
targetDirectory
.
path
,
'Payload'
,
'bundle.app'
));
bundleAppDir
.
createSync
(
recursive:
true
);
...
...
@@ -357,7 +342,7 @@ void main() {
globals
.
fs
.
file
(
globals
.
fs
.
path
.
join
(
bundleAppDir
.
path
,
'Info.plist'
))
.
createSync
();
}
)
;
};
final
PrebuiltIOSApp
iosApp
=
IOSApp
.
fromPrebuiltApp
(
globals
.
fs
.
file
(
'app.ipa'
))
as
PrebuiltIOSApp
;
expect
(
testLogger
.
errorText
,
isEmpty
);
expect
(
iosApp
.
bundleDir
.
path
,
endsWith
(
'bundle.app'
));
...
...
@@ -399,8 +384,7 @@ void main() {
final
Map
<
Type
,
Generator
>
overrides
=
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
.
test
(),
ProcessManager:
()
=>
FakeProcessManager
.
any
(),
Platform:
_kNoColorTerminalPlatform
,
OperatingSystemUtils:
()
=>
MockOperatingSystemUtils
(),
OperatingSystemUtils:
()
=>
FakeOperatingSystemUtils
(),
};
testUsingContext
(
'Error on non-existing file'
,
()
{
...
...
@@ -702,4 +686,27 @@ N: android=http://schemas.android.com/apk/res/android
A: android:name(0x01010003)="android.permission.INTERNET" (Raw: "android.permission.INTERNET")
'''
;
class
MockOperatingSystemUtils
extends
Mock
implements
OperatingSystemUtils
{
}
class
FakeOperatingSystemUtils
extends
Fake
implements
OperatingSystemUtils
{
void
Function
(
File
,
Directory
)
onUnzip
;
@override
void
unzip
(
File
file
,
Directory
targetDirectory
)
{
onUnzip
?.
call
(
file
,
targetDirectory
);
}
}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
@override
bool
platformToolsAvailable
;
@override
bool
licensesAvailable
;
@override
AndroidSdkVersion
latestVersion
;
}
class
FakeAndroidSdkVersion
extends
Fake
implements
AndroidSdkVersion
{
@override
String
aaptPath
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment