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
945e0df1
Unverified
Commit
945e0df1
authored
Mar 04, 2021
by
Jonah Williams
Committed by
GitHub
Mar 04, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove several AndroidSdk Mocks (#77264)
parent
6b500fa7
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
126 deletions
+48
-126
build_apk_test.dart
...r_tools/test/commands.shard/permeable/build_apk_test.dart
+9
-4
build_appbundle_test.dart
...s/test/commands.shard/permeable/build_appbundle_test.dart
+15
-103
android_device_start_test.dart
...test/general.shard/android/android_device_start_test.dart
+9
-5
android_device_stop_test.dart
.../test/general.shard/android/android_device_stop_test.dart
+3
-3
android_device_test.dart
...tools/test/general.shard/android/android_device_test.dart
+7
-5
gradle_test.dart
...flutter_tools/test/general.shard/android/gradle_test.dart
+5
-6
No files found.
packages/flutter_tools/test/commands.shard/permeable/build_apk_test.dart
View file @
945e0df1
...
...
@@ -23,7 +23,7 @@ import 'package:process/process.dart';
import
'../../src/android_common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/mocks.dart'
;
import
'../../src/mocks.dart'
hide
MockAndroidSdk
;
void
main
(
)
{
Cache
.
disableLocking
();
...
...
@@ -173,8 +173,7 @@ void main() {
return
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
0
,
''
,
''
));
});
mockAndroidSdk
=
MockAndroidSdk
();
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
globals
.
fs
.
directory
(
'irrelevant'
));
mockAndroidSdk
=
FakeAndroidSdk
(
globals
.
fs
.
directory
(
'irrelevant'
));
});
tearDown
(()
{
...
...
@@ -530,5 +529,11 @@ Future<BuildApkCommand> runBuildApkCommand(
return
command
;
}
class
MockAndroidSdk
extends
Mock
implements
AndroidSdk
{}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
FakeAndroidSdk
(
this
.
directory
);
@override
final
Directory
directory
;
}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
packages/flutter_tools/test/commands.shard/permeable/build_appbundle_test.dart
View file @
945e0df1
...
...
@@ -16,13 +16,12 @@ import 'package:flutter_tools/src/commands/build_appbundle.dart';
import
'package:flutter_tools/src/globals.dart'
as
globals
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:flutter_tools/src/reporting/reporting.dart'
;
import
'package:mockito/mockito.dart'
;
import
'package:process/process.dart'
;
import
'package:test/fake.dart'
;
import
'../../src/android_common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/mocks.dart'
;
void
main
(
)
{
Cache
.
disableLocking
();
...
...
@@ -97,64 +96,15 @@ void main() {
group
(
'Gradle'
,
()
{
Directory
tempDir
;
ProcessManager
mockProcessManager
;
MockAndroidSdk
mockAndroidSdk
;
String
gradlew
;
FakeProcessManager
processManager
;
FakeAndroidSdk
mockAndroidSdk
;
TestUsage
testUsage
;
setUp
(()
{
testUsage
=
TestUsage
();
tempDir
=
globals
.
fs
.
systemTempDirectory
.
createTempSync
(
'flutter_tools_packages_test.'
);
gradlew
=
globals
.
fs
.
path
.
join
(
tempDir
.
path
,
'flutter_project'
,
'android'
,
globals
.
platform
.
isWindows
?
'gradlew.bat'
:
'gradlew'
);
mockProcessManager
=
MockProcessManager
();
when
(
mockProcessManager
.
run
(<
String
>[
gradlew
,
'-v'
],
environment:
anyNamed
(
'environment'
)))
.
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
0
,
''
,
''
)));
when
(
mockProcessManager
.
run
(<
String
>[
gradlew
,
'app:properties'
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
)))
.
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
0
,
'buildDir: irrelevant'
,
''
)));
when
(
mockProcessManager
.
run
(<
String
>[
gradlew
,
'app:tasks'
,
'--all'
,
'--console=auto'
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
)))
.
thenAnswer
((
_
)
=>
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
0
,
'assembleRelease'
,
''
)));
// Fallback with error.
final
Process
process
=
createMockProcess
(
exitCode:
1
);
when
(
mockProcessManager
.
start
(
any
,
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
)))
.
thenAnswer
((
_
)
=>
Future
<
Process
>.
value
(
process
));
when
(
mockProcessManager
.
canRun
(
any
)).
thenReturn
(
false
);
when
(
mockProcessManager
.
runSync
(
argThat
(
contains
(
contains
(
'gen_snapshot'
))),
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
),
)).
thenReturn
(
ProcessResult
(
0
,
255
,
''
,
''
));
when
(
mockProcessManager
.
runSync
(
<
String
>[
'/usr/bin/xcode-select'
,
'--print-path'
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
),
)).
thenReturn
(
ProcessResult
(
0
,
0
,
''
,
''
));
when
(
mockProcessManager
.
run
(
<
String
>[
'which'
,
'pod'
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
),
)).
thenAnswer
((
_
)
{
return
Future
<
ProcessResult
>.
value
(
ProcessResult
(
0
,
0
,
''
,
''
));
});
mockAndroidSdk
=
MockAndroidSdk
();
when
(
mockAndroidSdk
.
licensesAvailable
).
thenReturn
(
true
);
when
(
mockAndroidSdk
.
platformToolsAvailable
).
thenReturn
(
true
);
when
(
mockAndroidSdk
.
validateSdkWellFormed
()).
thenReturn
(
const
<
String
>[]);
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
globals
.
fs
.
directory
(
'irrelevant'
));
processManager
=
FakeProcessManager
.
any
();
mockAndroidSdk
=
FakeAndroidSdk
(
globals
.
fs
.
directory
(
'irrelevant'
));
});
tearDown
(()
{
...
...
@@ -178,7 +128,7 @@ void main() {
overrides:
<
Type
,
Generator
>{
AndroidSdk:
()
=>
null
,
FlutterProjectFactory:
()
=>
FakeFlutterProjectFactory
(
tempDir
),
ProcessManager:
()
=>
mockP
rocessManager
,
ProcessManager:
()
=>
p
rocessManager
,
});
});
...
...
@@ -192,25 +142,6 @@ void main() {
.
childFile
(
'gradle.properties'
)
.
writeAsStringSync
(
'android.useAndroidX=false'
);
when
(
mockProcessManager
.
start
(
<
String
>[
gradlew
,
'-q'
,
'-Ptarget-platform=android-arm,android-arm64,android-x64'
,
'-Ptarget=
${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}
'
,
'-Ptrack-widget-creation=true'
,
'assembleRelease'
,
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
),
)).
thenAnswer
((
_
)
{
return
Future
<
Process
>.
value
(
createMockProcess
(
exitCode:
0
,
stdout:
''
,
),
);
});
// The command throws a [ToolExit] because it expects an AAB in the file system.
await
expectLater
(()
async
{
await
runBuildAppBundleCommand
(
...
...
@@ -242,7 +173,7 @@ void main() {
overrides:
<
Type
,
Generator
>{
AndroidSdk:
()
=>
mockAndroidSdk
,
FlutterProjectFactory:
()
=>
FakeFlutterProjectFactory
(
tempDir
),
ProcessManager:
()
=>
mockP
rocessManager
,
ProcessManager:
()
=>
p
rocessManager
,
Usage:
()
=>
testUsage
,
});
...
...
@@ -250,25 +181,6 @@ void main() {
final
String
projectPath
=
await
createProject
(
tempDir
,
arguments:
<
String
>[
'--no-pub'
,
'--template=app'
]);
when
(
mockProcessManager
.
start
(
<
String
>[
gradlew
,
'-q'
,
'-Ptarget-platform=android-arm,android-arm64,android-x64'
,
'-Ptarget=
${globals.fs.path.join(tempDir.path, 'flutter_project', 'lib', 'main.dart')}
'
,
'-Ptrack-widget-creation=true'
,
'assembleRelease'
,
],
workingDirectory:
anyNamed
(
'workingDirectory'
),
environment:
anyNamed
(
'environment'
),
)).
thenAnswer
((
_
)
{
return
Future
<
Process
>.
value
(
createMockProcess
(
exitCode:
0
,
stdout:
''
,
),
);
});
// The command throws a [ToolExit] because it expects an AAB in the file system.
await
expectLater
(()
async
{
await
runBuildAppBundleCommand
(
...
...
@@ -278,11 +190,11 @@ void main() {
expect
(
testLogger
.
statusText
,
n
ot
(
containsIgnoringWhitespace
(
"Your app isn't using AndroidX"
)),
isN
ot
(
containsIgnoringWhitespace
(
"Your app isn't using AndroidX"
)),
);
expect
(
testLogger
.
statusText
,
n
ot
(
isN
ot
(
containsIgnoringWhitespace
(
'To avoid potential build failures, you can quickly migrate your app by '
'following the steps on https://goo.gl/CP92wY'
),
...
...
@@ -301,7 +213,7 @@ void main() {
overrides:
<
Type
,
Generator
>{
AndroidSdk:
()
=>
mockAndroidSdk
,
FlutterProjectFactory:
()
=>
FakeFlutterProjectFactory
(
tempDir
),
ProcessManager:
()
=>
mockP
rocessManager
,
ProcessManager:
()
=>
p
rocessManager
,
Usage:
()
=>
testUsage
,
});
});
...
...
@@ -322,9 +234,9 @@ Future<BuildAppBundleCommand> runBuildAppBundleCommand(
return
command
;
}
Matcher
not
(
Matcher
target
){
return
isNot
(
target
);
}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
FakeAndroidSdk
(
this
.
directory
);
class
MockAndroidSdk
extends
Mock
implements
AndroidSdk
{}
class
MockProcessManager
extends
Mock
implements
ProcessManager
{}
@override
final
Directory
directory
;
}
packages/flutter_tools/test/general.shard/android/android_device_start_test.dart
View file @
945e0df1
...
...
@@ -13,7 +13,7 @@ import 'package:flutter_tools/src/base/logger.dart';
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/device.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
...
...
@@ -49,9 +49,7 @@ void main() {
setUp
(()
{
processManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]);
fileSystem
=
MemoryFileSystem
.
test
();
androidSdk
=
MockAndroidSdk
();
when
(
androidSdk
.
adbPath
).
thenReturn
(
'adb'
);
when
(
androidSdk
.
licensesAvailable
).
thenReturn
(
false
);
androidSdk
=
FakeAndroidSdk
();
});
for
(
final
TargetPlatform
targetPlatform
in
<
TargetPlatform
>[
...
...
@@ -291,4 +289,10 @@ void main() {
});
}
class
MockAndroidSdk
extends
Mock
implements
AndroidSdk
{}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
@override
String
get
adbPath
=>
'adb'
;
@override
bool
get
licensesAvailable
=>
false
;
}
packages/flutter_tools/test/general.shard/android/android_device_stop_test.dart
View file @
945e0df1
...
...
@@ -9,7 +9,7 @@ import 'package:flutter_tools/src/android/android_device.dart';
import
'package:flutter_tools/src/android/android_sdk.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
...
...
@@ -17,7 +17,7 @@ import '../../src/context.dart';
void
main
(
)
{
testWithoutContext
(
'AndroidDevice.stopApp handles a null ApplicationPackage'
,
()
async
{
final
AndroidDevice
androidDevice
=
AndroidDevice
(
'1234'
,
androidSdk:
Mock
AndroidSdk
(),
androidSdk:
Fake
AndroidSdk
(),
fileSystem:
MemoryFileSystem
.
test
(),
logger:
BufferLogger
.
test
(),
platform:
FakePlatform
(
operatingSystem:
'linux'
),
...
...
@@ -28,4 +28,4 @@ void main() {
});
}
class
MockAndroidSdk
extends
Mock
implements
AndroidSdk
{}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{}
packages/flutter_tools/test/general.shard/android/android_device_test.dart
View file @
945e0df1
...
...
@@ -19,7 +19,7 @@ import 'package:flutter_tools/src/base/platform.dart';
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/device.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'
;
...
...
@@ -63,7 +63,7 @@ void main() {
platform:
FakePlatform
(
operatingSystem:
'macos'
)
);
// Parsing succeed
e
s despite the error.
// Parsing succeeds despite the error.
expect
(
await
windowsDevice
.
isLocalEmulator
,
true
);
// Parsing fails and these default to false.
...
...
@@ -466,8 +466,7 @@ AndroidDevice setUpAndroidDevice({
Platform
platform
,
AndroidConsoleSocketFactory
androidConsoleSocketFactory
=
kAndroidConsoleSocketFactory
,
})
{
androidSdk
??=
MockAndroidSdk
();
when
(
androidSdk
.
adbPath
).
thenReturn
(
'adb'
);
androidSdk
??=
FakeAndroidSdk
();
return
AndroidDevice
(
id
??
'1234'
,
logger:
BufferLogger
.
test
(),
platform:
platform
??
FakePlatform
(
operatingSystem:
'linux'
),
...
...
@@ -478,7 +477,10 @@ AndroidDevice setUpAndroidDevice({
);
}
class
MockAndroidSdk
extends
Mock
implements
AndroidSdk
{}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{
@override
String
get
adbPath
=>
'adb'
;
}
const
String
kAdbShellGetprop
=
'''
[dalvik.vm.dex2oat-Xms]: [64m]
...
...
packages/flutter_tools/test/general.shard/android/gradle_test.dart
View file @
945e0df1
...
...
@@ -630,7 +630,7 @@ flutter:
group
(
'buildPluginsAsAar'
,
()
{
FileSystem
fs
;
FakeProcessManager
fakeProcessManager
;
MockAndroidSdk
mockA
ndroidSdk
;
FakeAndroidSdk
a
ndroidSdk
;
AndroidGradleBuilder
builder
;
BufferLogger
logger
;
...
...
@@ -638,8 +638,7 @@ flutter:
logger
=
BufferLogger
.
test
();
fs
=
MemoryFileSystem
.
test
();
fakeProcessManager
=
FakeProcessManager
.
list
(<
FakeCommand
>[]);
mockAndroidSdk
=
MockAndroidSdk
();
when
(
mockAndroidSdk
.
directory
).
thenReturn
(
fs
.
directory
(
'irrelevant'
));
androidSdk
=
FakeAndroidSdk
();
builder
=
AndroidGradleBuilder
(
logger:
logger
,
processManager:
fakeProcessManager
,
...
...
@@ -761,7 +760,7 @@ plugin2=${plugin2.path}
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
<
Type
,
Generator
>{
AndroidSdk:
()
=>
mockA
ndroidSdk
,
AndroidSdk:
()
=>
a
ndroidSdk
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
fakeProcessManager
,
GradleUtils:
()
=>
FakeGradleUtils
(),
...
...
@@ -808,7 +807,7 @@ plugin1=${plugin1.path}
);
expect
(
fakeProcessManager
.
hasRemainingExpectations
,
isFalse
);
},
overrides:
<
Type
,
Generator
>{
AndroidSdk:
()
=>
mockA
ndroidSdk
,
AndroidSdk:
()
=>
a
ndroidSdk
,
FileSystem:
()
=>
fs
,
ProcessManager:
()
=>
fakeProcessManager
,
GradleUtils:
()
=>
FakeGradleUtils
(),
...
...
@@ -1031,6 +1030,6 @@ class FakeGradleUtils extends GradleUtils {
}
}
class
MockAndroidSdk
extends
Mock
implements
AndroidSdk
{}
class
FakeAndroidSdk
extends
Fake
implements
AndroidSdk
{}
class
MockAndroidProject
extends
Mock
implements
AndroidProject
{}
class
MockFlutterProject
extends
Mock
implements
FlutterProject
{}
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