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
c2e85e67
Unverified
Commit
c2e85e67
authored
Aug 08, 2020
by
Jonah Williams
Committed by
GitHub
Aug 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[null-safety] remove more usage of mockito from the framework tests (#62936)
parent
191c7cbe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
151 additions
and
45 deletions
+151
-45
animated_icons_test.dart
packages/flutter/test/material/animated_icons_test.dart
+80
-15
custom_paint_test.dart
packages/flutter/test/widgets/custom_paint_test.dart
+23
-11
routes_test.dart
packages/flutter/test/widgets/routes_test.dart
+48
-19
No files found.
packages/flutter/test/material/animated_icons_test.dart
View file @
c2e85e67
...
...
@@ -8,11 +8,75 @@ import 'dart:math' as math show pi;
import
'package:flutter/material.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../flutter_test_alternative.dart'
show
Fake
;
import
'../widgets/semantics_tester.dart'
;
class
MockCanvas
extends
Mock
implements
Canvas
{}
class
MockCanvas
extends
Fake
implements
Canvas
{
Path
capturedPath
;
Paint
capturedPaint
;
@override
void
drawPath
(
Path
path
,
Paint
paint
)
{
capturedPath
=
path
;
capturedPaint
=
paint
;
}
double
capturedSx
;
double
capturedSy
;
@override
void
scale
(
double
sx
,
[
double
sy
])
{
capturedSx
=
sx
;
capturedSy
=
sy
;
}
final
List
<
RecordedCanvasCall
>
invocations
=
<
RecordedCanvasCall
>[];
@override
void
rotate
(
double
radians
)
{
invocations
.
add
(
RecordedRotate
(
radians
));
}
@override
void
translate
(
double
dx
,
double
dy
)
{
invocations
.
add
(
RecordedTranslate
(
dx
,
dy
));
}
}
@immutable
abstract
class
RecordedCanvasCall
{
const
RecordedCanvasCall
();
}
class
RecordedRotate
extends
RecordedCanvasCall
{
const
RecordedRotate
(
this
.
radians
);
final
double
radians
;
@override
bool
operator
==(
Object
other
)
{
return
other
is
RecordedRotate
&&
other
.
radians
==
radians
;
}
@override
int
get
hashCode
=>
radians
.
hashCode
;
}
class
RecordedTranslate
extends
RecordedCanvasCall
{
const
RecordedTranslate
(
this
.
dx
,
this
.
dy
);
final
double
dx
;
final
double
dy
;
@override
bool
operator
==(
Object
other
)
{
return
other
is
RecordedTranslate
&&
other
.
dx
==
dx
&&
other
.
dy
==
dy
;
}
@override
int
get
hashCode
=>
hashValues
(
dx
,
dy
);
}
void
main
(
)
{
testWidgets
(
'IconTheme color'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -33,7 +97,7 @@ void main() {
final
CustomPaint
customPaint
=
tester
.
widget
(
find
.
byType
(
CustomPaint
));
final
MockCanvas
canvas
=
MockCanvas
();
customPaint
.
painter
.
paint
(
canvas
,
const
Size
(
48.0
,
48.0
));
verify
(
canvas
.
drawPath
(
any
,
argThat
(
hasColor
(
0xFF666666
))
));
expect
(
canvas
.
capturedPaint
,
hasColor
(
0xFF666666
));
});
testWidgets
(
'IconTheme opacity'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -55,7 +119,7 @@ void main() {
final
CustomPaint
customPaint
=
tester
.
widget
(
find
.
byType
(
CustomPaint
));
final
MockCanvas
canvas
=
MockCanvas
();
customPaint
.
painter
.
paint
(
canvas
,
const
Size
(
48.0
,
48.0
));
verify
(
canvas
.
drawPath
(
any
,
argThat
(
hasColor
(
0x80666666
))
));
expect
(
canvas
.
capturedPaint
,
hasColor
(
0x80666666
));
});
testWidgets
(
'color overrides IconTheme color'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -77,7 +141,7 @@ void main() {
final
CustomPaint
customPaint
=
tester
.
widget
(
find
.
byType
(
CustomPaint
));
final
MockCanvas
canvas
=
MockCanvas
();
customPaint
.
painter
.
paint
(
canvas
,
const
Size
(
48.0
,
48.0
));
verify
(
canvas
.
drawPath
(
any
,
argThat
(
hasColor
(
0xFF0000FF
))
));
expect
(
canvas
.
capturedPaint
,
hasColor
(
0xFF0000FF
));
});
testWidgets
(
'IconTheme size'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -100,7 +164,8 @@ void main() {
final
MockCanvas
canvas
=
MockCanvas
();
customPaint
.
painter
.
paint
(
canvas
,
const
Size
(
12.0
,
12.0
));
// arrow_menu default size is 48x48 so we expect it to be scaled by 0.25.
verify
(
canvas
.
scale
(
0.25
,
0.25
));
expect
(
canvas
.
capturedSx
,
0.25
);
expect
(
canvas
.
capturedSy
,
0.25
);
});
testWidgets
(
'size overridesIconTheme size'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -124,7 +189,8 @@ void main() {
final
MockCanvas
canvas
=
MockCanvas
();
customPaint
.
painter
.
paint
(
canvas
,
const
Size
(
12.0
,
12.0
));
// arrow_menu default size is 48x48 so we expect it to be scaled by 2.
verify
(
canvas
.
scale
(
2.0
,
2.0
));
expect
(
canvas
.
capturedSx
,
2
);
expect
(
canvas
.
capturedSy
,
2
);
});
testWidgets
(
'Semantic label'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -165,9 +231,9 @@ void main() {
final
CustomPaint
customPaint
=
tester
.
widget
(
find
.
byType
(
CustomPaint
));
final
MockCanvas
canvas
=
MockCanvas
();
customPaint
.
painter
.
paint
(
canvas
,
const
Size
(
48.0
,
48.0
));
verifyInOrder
(<
void
>[
canvas
.
r
otate
(
math
.
pi
),
canvas
.
translate
(-
48.0
,
-
48.0
),
expect
(
canvas
.
invocations
,
const
<
RecordedCanvasCall
>[
RecordedR
otate
(
math
.
pi
),
RecordedTranslate
(-
48
,
-
48
),
]);
});
...
...
@@ -189,8 +255,7 @@ void main() {
final
CustomPaint
customPaint
=
tester
.
widget
(
find
.
byType
(
CustomPaint
));
final
MockCanvas
canvas
=
MockCanvas
();
customPaint
.
painter
.
paint
(
canvas
,
const
Size
(
48.0
,
48.0
));
verifyNever
(
canvas
.
rotate
(
any
));
verifyNever
(
canvas
.
translate
(
any
,
any
));
expect
(
canvas
.
invocations
,
isEmpty
);
});
testWidgets
(
'Inherited text direction overridden'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -212,9 +277,9 @@ void main() {
final
CustomPaint
customPaint
=
tester
.
widget
(
find
.
byType
(
CustomPaint
));
final
MockCanvas
canvas
=
MockCanvas
();
customPaint
.
painter
.
paint
(
canvas
,
const
Size
(
48.0
,
48.0
));
verifyInOrder
(<
void
>[
canvas
.
r
otate
(
math
.
pi
),
canvas
.
translate
(-
48.0
,
-
48.0
),
expect
(
canvas
.
invocations
,
const
<
RecordedCanvasCall
>[
RecordedR
otate
(
math
.
pi
),
RecordedTranslate
(-
48
,
-
48
),
]);
});
}
...
...
packages/flutter/test/widgets/custom_paint_test.dart
View file @
c2e85e67
...
...
@@ -7,7 +7,8 @@
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../flutter_test_alternative.dart'
show
Fake
;
class
TestCustomPainter
extends
CustomPainter
{
TestCustomPainter
({
this
.
log
,
this
.
name
});
...
...
@@ -39,9 +40,23 @@ class TestCustomPainterWithCustomSemanticsBuilder extends TestCustomPainter {
};
}
class
MockCanvas
extends
Mock
implements
Canvas
{}
class
MockCanvas
extends
Fake
implements
Canvas
{
int
saveCount
=
0
;
int
saveCountDelta
=
1
;
class
MockPaintingContext
extends
Mock
implements
PaintingContext
{}
@override
int
getSaveCount
()
{
return
saveCount
+=
saveCountDelta
;
}
@override
void
save
()
{
}
}
class
MockPaintingContext
extends
Fake
implements
PaintingContext
{
@override
final
MockCanvas
canvas
=
MockCanvas
();
}
void
main
(
)
{
testWidgets
(
'Control test for custom painting'
,
(
WidgetTester
tester
)
async
{
...
...
@@ -76,11 +91,8 @@ void main() {
painter:
TestCustomPainter
(
log:
log
),
));
final
RenderCustomPaint
renderCustom
=
target
.
currentContext
.
findRenderObject
()
as
RenderCustomPaint
;
final
Canvas
canvas
=
MockCanvas
();
int
saveCount
=
0
;
when
(
canvas
.
getSaveCount
()).
thenAnswer
((
_
)
=>
saveCount
++);
final
PaintingContext
paintingContext
=
MockPaintingContext
();
when
(
paintingContext
.
canvas
).
thenReturn
(
canvas
);
final
MockPaintingContext
paintingContext
=
MockPaintingContext
();
final
MockCanvas
canvas
=
paintingContext
.
canvas
;
FlutterError
getError
()
{
FlutterError
error
;
...
...
@@ -104,7 +116,7 @@ void main() {
' matching call to restore().
\n
'
));
when
(
canvas
.
getSaveCount
()).
thenAnswer
((
_
)
=>
saveCount
--)
;
canvas
.
saveCountDelta
=
-
1
;
error
=
getError
();
expect
(
error
.
toStringDeep
(),
equalsIgnoringHashCodes
(
'FlutterError
\n
'
...
...
@@ -117,11 +129,11 @@ void main() {
' saveLayer().
\n
'
));
when
(
canvas
.
getSaveCount
()).
thenAnswer
((
_
)
=>
saveCount
+=
2
)
;
canvas
.
saveCountDelta
=
2
;
error
=
getError
();
expect
(
error
.
toStringDeep
(),
contains
(
'2 more times'
));
when
(
canvas
.
getSaveCount
()).
thenAnswer
((
_
)
=>
saveCount
-=
2
)
;
canvas
.
saveCountDelta
=
-
2
;
error
=
getError
();
expect
(
error
.
toStringDeep
(),
contains
(
'2 more times'
));
});
...
...
packages/flutter/test/widgets/routes_test.dart
View file @
c2e85e67
...
...
@@ -11,8 +11,8 @@ import 'package:flutter/material.dart';
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:mockito/mockito.dart'
;
import
'../flutter_test_alternative.dart'
show
Fake
;
import
'semantics_tester.dart'
;
final
List
<
String
>
results
=
<
String
>[];
...
...
@@ -452,60 +452,64 @@ void main() {
group
(
'PageRouteObserver'
,
()
{
test
(
'calls correct listeners'
,
()
{
final
RouteObserver
<
PageRoute
<
dynamic
>>
observer
=
RouteObserver
<
PageRoute
<
dynamic
>>();
final
RouteAware
pageRouteAware1
=
MockRouteAware
();
final
Mock
RouteAware
pageRouteAware1
=
MockRouteAware
();
final
MockPageRoute
route1
=
MockPageRoute
();
observer
.
subscribe
(
pageRouteAware1
,
route1
);
verify
(
pageRouteAware1
.
didPush
()).
called
(
1
);
expect
(
pageRouteAware1
.
didPushCount
,
1
);
final
RouteAware
pageRouteAware2
=
MockRouteAware
();
final
Mock
RouteAware
pageRouteAware2
=
MockRouteAware
();
final
MockPageRoute
route2
=
MockPageRoute
();
observer
.
didPush
(
route2
,
route1
);
verify
(
pageRouteAware1
.
didPushNext
()).
called
(
1
);
expect
(
pageRouteAware1
.
didPushNextCount
,
1
);
observer
.
subscribe
(
pageRouteAware2
,
route2
);
verify
(
pageRouteAware2
.
didPush
()).
called
(
1
);
expect
(
pageRouteAware2
.
didPushCount
,
1
);
observer
.
didPop
(
route2
,
route1
);
verify
(
pageRouteAware2
.
didPop
()).
called
(
1
);
verify
(
pageRouteAware1
.
didPopNext
()).
called
(
1
);
expect
(
pageRouteAware2
.
didPopCount
,
1
);
expect
(
pageRouteAware1
.
didPopNextCount
,
1
);
});
test
(
'does not call listeners for non-PageRoute'
,
()
{
final
RouteObserver
<
PageRoute
<
dynamic
>>
observer
=
RouteObserver
<
PageRoute
<
dynamic
>>();
final
RouteAware
pageRouteAware
=
MockRouteAware
();
final
Mock
RouteAware
pageRouteAware
=
MockRouteAware
();
final
MockPageRoute
pageRoute
=
MockPageRoute
();
final
MockRoute
route
=
MockRoute
();
observer
.
subscribe
(
pageRouteAware
,
pageRoute
);
verify
(
pageRouteAware
.
didPush
()
);
expect
(
pageRouteAware
.
didPushCount
,
1
);
observer
.
didPush
(
route
,
pageRoute
);
observer
.
didPop
(
route
,
pageRoute
);
verifyNoMoreInteractions
(
pageRouteAware
);
expect
(
pageRouteAware
.
didPushCount
,
1
);
expect
(
pageRouteAware
.
didPopCount
,
0
);
});
test
(
'does not call listeners when already subscribed'
,
()
{
final
RouteObserver
<
PageRoute
<
dynamic
>>
observer
=
RouteObserver
<
PageRoute
<
dynamic
>>();
final
RouteAware
pageRouteAware
=
MockRouteAware
();
final
Mock
RouteAware
pageRouteAware
=
MockRouteAware
();
final
MockPageRoute
pageRoute
=
MockPageRoute
();
observer
.
subscribe
(
pageRouteAware
,
pageRoute
);
observer
.
subscribe
(
pageRouteAware
,
pageRoute
);
verify
(
pageRouteAware
.
didPush
()).
called
(
1
);
expect
(
pageRouteAware
.
didPushCount
,
1
);
});
test
(
'does not call listeners when unsubscribed'
,
()
{
final
RouteObserver
<
PageRoute
<
dynamic
>>
observer
=
RouteObserver
<
PageRoute
<
dynamic
>>();
final
RouteAware
pageRouteAware
=
MockRouteAware
();
final
Mock
RouteAware
pageRouteAware
=
MockRouteAware
();
final
MockPageRoute
pageRoute
=
MockPageRoute
();
final
MockPageRoute
nextPageRoute
=
MockPageRoute
();
observer
.
subscribe
(
pageRouteAware
,
pageRoute
);
observer
.
subscribe
(
pageRouteAware
,
nextPageRoute
);
verify
(
pageRouteAware
.
didPush
()).
called
(
2
);
expect
(
pageRouteAware
.
didPushCount
,
2
);
observer
.
unsubscribe
(
pageRouteAware
);
observer
.
didPush
(
nextPageRoute
,
pageRoute
);
observer
.
didPop
(
nextPageRoute
,
pageRoute
);
verifyNoMoreInteractions
(
pageRouteAware
);
expect
(
pageRouteAware
.
didPushCount
,
2
);
expect
(
pageRouteAware
.
didPopCount
,
0
);
});
});
...
...
@@ -1790,11 +1794,36 @@ class ModifiedReverseTransitionDurationRoute<T> extends MaterialPageRoute<T> {
final
Duration
reverseTransitionDuration
;
}
class
MockPageRoute
extends
Mock
implements
PageRoute
<
dynamic
>
{
}
class
MockPageRoute
extends
Fake
implements
PageRoute
<
dynamic
>
{
}
class
MockRoute
extends
Fake
implements
Route
<
dynamic
>
{
}
class
MockRouteAware
extends
Fake
implements
RouteAware
{
int
didPushCount
=
0
;
int
didPushNextCount
=
0
;
int
didPopCount
=
0
;
int
didPopNextCount
=
0
;
class
MockRoute
extends
Mock
implements
Route
<
dynamic
>
{
}
@override
void
didPush
()
{
didPushCount
+=
1
;
}
class
MockRouteAware
extends
Mock
implements
RouteAware
{
}
@override
void
didPushNext
()
{
didPushNextCount
+=
1
;
}
@override
void
didPop
()
{
didPopCount
+=
1
;
}
@override
void
didPopNext
()
{
didPopNextCount
+=
1
;
}
}
class
TestPageRouteBuilder
extends
PageRouteBuilder
<
void
>
{
TestPageRouteBuilder
({
RoutePageBuilder
pageBuilder
})
:
super
(
pageBuilder:
pageBuilder
);
...
...
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