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
6192e420
Unverified
Commit
6192e420
authored
May 13, 2021
by
Jonah Williams
Committed by
GitHub
May 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] remove mocks from device test (#82472)
parent
96320ae7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
72 deletions
+81
-72
device_test.dart
packages/flutter_tools/test/general.shard/device_test.dart
+81
-72
No files found.
packages/flutter_tools/test/general.shard/device_test.dart
View file @
6192e420
...
...
@@ -15,10 +15,9 @@ import 'package:flutter_tools/src/build_info.dart';
import
'package:flutter_tools/src/device.dart'
;
import
'package:flutter_tools/src/project.dart'
;
import
'package:meta/meta.dart'
;
import
'package:
mockito/mockito
.dart'
;
import
'package:
test/fake
.dart'
;
import
'../src/common.dart'
;
import
'../src/context.dart'
;
import
'../src/fake_devices.dart'
;
void
main
(
)
{
...
...
@@ -184,18 +183,13 @@ void main() {
nonEphemeralOne
,
nonEphemeralTwo
,
];
final
MockTerminal
mockTerminal
=
MockTerminal
();
when
(
mockTerminal
.
stdinHasTerminal
).
thenReturn
(
true
);
when
(
mockTerminal
.
promptForCharInput
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
displayAcceptedCharacters:
false
,
logger:
anyNamed
(
'logger'
),
prompt:
anyNamed
(
'prompt'
),
)).
thenAnswer
((
Invocation
invocation
)
async
=>
'1'
);
final
FakeTerminal
terminal
=
FakeTerminal
()
..
setPrompt
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
'1'
);
final
DeviceManager
deviceManager
=
TestDeviceManager
(
devices
,
logger:
BufferLogger
.
test
(),
terminal:
mockT
erminal
,
terminal:
t
erminal
,
);
final
List
<
Device
>
filtered
=
await
deviceManager
.
findTargetDevices
(
FakeFlutterProject
());
...
...
@@ -209,19 +203,13 @@ void main() {
nonEphemeralOne
,
nonEphemeralTwo
,
];
final
MockTerminal
mockTerminal
=
MockTerminal
();
when
(
mockTerminal
.
stdinHasTerminal
).
thenReturn
(
true
);
when
(
mockTerminal
.
promptForCharInput
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
displayAcceptedCharacters:
false
,
logger:
anyNamed
(
'logger'
),
prompt:
anyNamed
(
'prompt'
),
)).
thenAnswer
((
Invocation
invocation
)
async
=>
'2'
);
final
FakeTerminal
terminal
=
FakeTerminal
()
..
setPrompt
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
'2'
);
final
DeviceManager
deviceManager
=
TestDeviceManager
(
devices
,
logger:
BufferLogger
.
test
(),
terminal:
mockT
erminal
,
terminal:
t
erminal
,
);
final
List
<
Device
>
filtered
=
await
deviceManager
.
findTargetDevices
(
FakeFlutterProject
());
...
...
@@ -236,19 +224,13 @@ void main() {
ephemeralTwo
,
];
final
MockTerminal
mockTerminal
=
MockTerminal
();
when
(
mockTerminal
.
stdinHasTerminal
).
thenReturn
(
true
);
when
(
mockTerminal
.
promptForCharInput
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
displayAcceptedCharacters:
false
,
logger:
anyNamed
(
'logger'
),
prompt:
anyNamed
(
'prompt'
),
)).
thenAnswer
((
Invocation
invocation
)
async
=>
'1'
);
final
FakeTerminal
terminal
=
FakeTerminal
()
..
setPrompt
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
'1'
);
final
DeviceManager
deviceManager
=
TestDeviceManager
(
devices
,
logger:
BufferLogger
.
test
(),
terminal:
mockT
erminal
,
terminal:
t
erminal
,
);
final
List
<
Device
>
filtered
=
await
deviceManager
.
findTargetDevices
(
FakeFlutterProject
());
...
...
@@ -262,19 +244,13 @@ void main() {
ephemeralOne
,
ephemeralTwo
,
];
final
MockTerminal
mockTerminal
=
MockTerminal
();
when
(
mockTerminal
.
stdinHasTerminal
).
thenReturn
(
true
);
when
(
mockTerminal
.
promptForCharInput
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
displayAcceptedCharacters:
false
,
logger:
anyNamed
(
'logger'
),
prompt:
anyNamed
(
'prompt'
),
)).
thenAnswer
((
Invocation
invocation
)
async
=>
'2'
);
final
FakeTerminal
terminal
=
FakeTerminal
()
..
setPrompt
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
'2'
);
final
DeviceManager
deviceManager
=
TestDeviceManager
(
devices
,
logger:
BufferLogger
.
test
(),
terminal:
mockT
erminal
,
terminal:
t
erminal
,
);
final
List
<
Device
>
filtered
=
await
deviceManager
.
findTargetDevices
(
FakeFlutterProject
());
...
...
@@ -291,19 +267,13 @@ void main() {
nonEphemeralTwo
,
];
final
MockTerminal
mockTerminal
=
MockTerminal
();
when
(
mockTerminal
.
stdinHasTerminal
).
thenReturn
(
true
);
when
(
mockTerminal
.
promptForCharInput
(<
String
>[
'1'
,
'2'
,
'3'
,
'4'
,
'q'
,
'Q'
],
displayAcceptedCharacters:
false
,
logger:
anyNamed
(
'logger'
),
prompt:
anyNamed
(
'prompt'
),
)).
thenAnswer
((
Invocation
invocation
)
async
=>
'3'
);
final
FakeTerminal
terminal
=
FakeTerminal
()
..
setPrompt
(<
String
>[
'1'
,
'2'
,
'3'
,
'4'
,
'q'
,
'Q'
],
'3'
);
final
DeviceManager
deviceManager
=
TestDeviceManager
(
devices
,
logger:
BufferLogger
.
test
(),
terminal:
mockT
erminal
,
terminal:
t
erminal
,
);
final
List
<
Device
>
filtered
=
await
deviceManager
.
findTargetDevices
(
FakeFlutterProject
());
...
...
@@ -319,19 +289,13 @@ void main() {
ephemeralTwo
,
];
final
MockTerminal
mockTerminal
=
MockTerminal
();
when
(
mockTerminal
.
stdinHasTerminal
).
thenReturn
(
true
);
when
(
mockTerminal
.
promptForCharInput
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
displayAcceptedCharacters:
false
,
logger:
anyNamed
(
'logger'
),
prompt:
anyNamed
(
'prompt'
),
)).
thenAnswer
((
Invocation
invocation
)
async
=>
'q'
);
final
FakeTerminal
terminal
=
FakeTerminal
()
..
setPrompt
(<
String
>[
'1'
,
'2'
,
'q'
,
'Q'
],
'q'
);
final
DeviceManager
deviceManager
=
TestDeviceManager
(
devices
,
logger:
BufferLogger
.
test
(),
terminal:
mockT
erminal
,
terminal:
t
erminal
,
);
await
expectLater
(
()
async
=>
deviceManager
.
findTargetDevices
(
FakeFlutterProject
()),
...
...
@@ -429,14 +393,13 @@ void main() {
final
List
<
Device
>
devices
=
<
Device
>[
ephemeralOne
,
];
final
MockDeviceDiscovery
mockDeviceDiscovery
=
MockDeviceDiscovery
();
when
(
mockDeviceDiscovery
.
supportsPlatform
).
thenReturn
(
true
);
when
(
mockDeviceDiscovery
.
devices
).
thenAnswer
((
_
)
async
=>
devices
);
final
MockDeviceDiscovery
deviceDiscovery
=
MockDeviceDiscovery
()
..
deviceValues
=
devices
;
final
DeviceManager
deviceManager
=
TestDeviceManager
(
<
Device
>[],
deviceDiscoveryOverrides:
<
DeviceDiscovery
>[
mockD
eviceDiscovery
d
eviceDiscovery
],
logger:
BufferLogger
.
test
(),
terminal:
Terminal
.
test
(),
...
...
@@ -447,24 +410,22 @@ void main() {
);
expect
(
filtered
.
single
,
ephemeralOne
);
verify
(
mockDeviceDiscovery
.
devices
).
called
(
1
);
verifyNever
(
mockDeviceDiscovery
.
discoverDevices
(
timeout:
anyNamed
(
'timeout'
))
);
expect
(
deviceDiscovery
.
devicesCalled
,
1
);
expect
(
deviceDiscovery
.
discoverDevicesCalled
,
0
);
});
test
Using
Context
(
'refreshes device cache with a timeout'
,
()
async
{
test
Without
Context
(
'refreshes device cache with a timeout'
,
()
async
{
final
List
<
Device
>
devices
=
<
Device
>[
ephemeralOne
,
];
const
Duration
timeout
=
Duration
(
seconds:
2
);
final
MockDeviceDiscovery
mockDeviceDiscovery
=
MockDeviceDiscovery
();
when
(
mockDeviceDiscovery
.
supportsPlatform
).
thenReturn
(
true
);
when
(
mockDeviceDiscovery
.
discoverDevices
(
timeout:
timeout
)).
thenAnswer
((
_
)
async
=>
devices
);
when
(
mockDeviceDiscovery
.
devices
).
thenAnswer
((
_
)
async
=>
devices
);
final
MockDeviceDiscovery
deviceDiscovery
=
MockDeviceDiscovery
()
..
deviceValues
=
devices
;
final
DeviceManager
deviceManager
=
TestDeviceManager
(
<
Device
>[],
deviceDiscoveryOverrides:
<
DeviceDiscovery
>[
mockD
eviceDiscovery
d
eviceDiscovery
],
logger:
BufferLogger
.
test
(),
terminal:
Terminal
.
test
(),
...
...
@@ -476,13 +437,13 @@ void main() {
);
expect
(
filtered
.
single
,
ephemeralOne
);
verify
(
mockDeviceDiscovery
.
devices
).
called
(
1
);
verify
(
mockDeviceDiscovery
.
discoverDevices
(
timeout:
anyNamed
(
'timeout'
))).
called
(
1
);
expect
(
deviceDiscovery
.
devicesCalled
,
1
);
expect
(
deviceDiscovery
.
discoverDevicesCalled
,
1
);
});
});
group
(
'JSON encode devices'
,
()
{
test
Using
Context
(
'Consistency of JSON representation'
,
()
async
{
test
Without
Context
(
'Consistency of JSON representation'
,
()
async
{
expect
(
// This tests that fakeDevices is a list of tuples where "second" is the
// correct JSON representation of the "first". Actual values are irrelevant
...
...
@@ -534,8 +495,28 @@ class TestDeviceManager extends DeviceManager {
}
}
class
MockTerminal
extends
Mock
implements
AnsiTerminal
{}
class
MockDeviceDiscovery
extends
Mock
implements
DeviceDiscovery
{}
class
MockDeviceDiscovery
extends
Fake
implements
DeviceDiscovery
{
int
devicesCalled
=
0
;
int
discoverDevicesCalled
=
0
;
@override
bool
supportsPlatform
=
true
;
List
<
Device
>
deviceValues
=
<
Device
>[];
@override
Future
<
List
<
Device
>>
get
devices
async
{
devicesCalled
+=
1
;
return
deviceValues
;
}
@override
Future
<
List
<
Device
>>
discoverDevices
({
Duration
timeout
})
async
{
discoverDevicesCalled
+=
1
;
return
deviceValues
;
}
}
class
FakeFlutterProject
extends
Fake
implements
FlutterProject
{}
class
LongPollingDeviceDiscovery
extends
PollingDeviceDiscovery
{
...
...
@@ -579,3 +560,31 @@ class ThrowingPollingDeviceDiscovery extends PollingDeviceDiscovery {
@override
bool
get
canListAnything
=>
true
;
}
class
FakeTerminal
extends
Fake
implements
Terminal
{
@override
bool
stdinHasTerminal
=
true
;
@override
bool
usesTerminalUi
=
true
;
void
setPrompt
(
List
<
String
>
characters
,
String
result
)
{
_nextPrompt
=
characters
;
_nextResult
=
result
;
}
List
<
String
>
_nextPrompt
;
String
_nextResult
;
@override
Future
<
String
>
promptForCharInput
(
List
<
String
>
acceptedCharacters
,
{
Logger
logger
,
String
prompt
,
int
defaultChoiceIndex
,
bool
displayAcceptedCharacters
=
true
,
})
async
{
expect
(
acceptedCharacters
,
_nextPrompt
);
return
_nextResult
;
}
}
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