@@ -12,7 +12,7 @@ class SamplePluginPlatform extends PlatformInterface {
12
12
static final Object _token = Object ();
13
13
14
14
static set instance (SamplePluginPlatform instance) {
15
- PlatformInterface .verifyToken (instance, _token);
15
+ PlatformInterface .verify (instance, _token);
16
16
// A real implementation would set a static instance field here.
17
17
}
18
18
}
@@ -26,20 +26,81 @@ class ImplementsSamplePluginPlatformUsingMockPlatformInterfaceMixin extends Mock
26
26
27
27
class ExtendsSamplePluginPlatform extends SamplePluginPlatform {}
28
28
29
+ class ConstTokenPluginPlatform extends PlatformInterface {
30
+ ConstTokenPluginPlatform () : super (token: _token);
31
+
32
+ static const Object _token = Object (); // invalid
33
+
34
+ static set instance (ConstTokenPluginPlatform instance) {
35
+ PlatformInterface .verify (instance, _token);
36
+ }
37
+ }
38
+
39
+ class ExtendsConstTokenPluginPlatform extends ConstTokenPluginPlatform {}
40
+
41
+ class VerifyTokenPluginPlatform extends PlatformInterface {
42
+ VerifyTokenPluginPlatform () : super (token: _token);
43
+
44
+ static final Object _token = Object ();
45
+
46
+ static set instance (VerifyTokenPluginPlatform instance) {
47
+ PlatformInterface .verifyToken (instance, _token);
48
+ // A real implementation would set a static instance field here.
49
+ }
50
+ }
51
+
52
+ class ImplementsVerifyTokenPluginPlatform extends Mock
53
+ implements VerifyTokenPluginPlatform {}
54
+
55
+ class ImplementsVerifyTokenPluginPlatformUsingMockPlatformInterfaceMixin
56
+ extends Mock
57
+ with MockPlatformInterfaceMixin
58
+ implements VerifyTokenPluginPlatform {}
59
+
60
+ class ExtendsVerifyTokenPluginPlatform extends VerifyTokenPluginPlatform {}
61
+
29
62
void main () {
30
- test ('Cannot be implemented with `implements`' , () {
31
- expect (() {
32
- SamplePluginPlatform .instance = ImplementsSamplePluginPlatform ();
33
- }, throwsA (isA <AssertionError >()));
34
- });
63
+ group ('`verify`' , () {
64
+ test ('prevents implementation with `implements`' , () {
65
+ expect (() {
66
+ SamplePluginPlatform .instance = ImplementsSamplePluginPlatform ();
67
+ }, throwsA (isA <AssertionError >()));
68
+ });
69
+
70
+ test ('allows mocking with `implements`' , () {
71
+ final SamplePluginPlatform mock =
72
+ ImplementsSamplePluginPlatformUsingMockPlatformInterfaceMixin ();
73
+ SamplePluginPlatform .instance = mock;
74
+ });
35
75
36
- test ('Can be mocked with `implements`' , () {
37
- final SamplePluginPlatform mock =
38
- ImplementsSamplePluginPlatformUsingMockPlatformInterfaceMixin ();
39
- SamplePluginPlatform .instance = mock;
76
+ test ('allows extending' , () {
77
+ SamplePluginPlatform .instance = ExtendsSamplePluginPlatform ();
78
+ });
79
+
80
+ test ('prevents `const Object()` token' , () {
81
+ expect (() {
82
+ ConstTokenPluginPlatform .instance = ExtendsConstTokenPluginPlatform ();
83
+ }, throwsA (isA <AssertionError >()));
84
+ });
40
85
});
41
86
42
- test ('Can be extended' , () {
43
- SamplePluginPlatform .instance = ExtendsSamplePluginPlatform ();
87
+ // Tests of the earlier, to-be-deprecated `verifyToken` method
88
+ group ('`verifyToken`' , () {
89
+ test ('prevents implementation with `implements`' , () {
90
+ expect (() {
91
+ VerifyTokenPluginPlatform .instance =
92
+ ImplementsVerifyTokenPluginPlatform ();
93
+ }, throwsA (isA <AssertionError >()));
94
+ });
95
+
96
+ test ('allows mocking with `implements`' , () {
97
+ final VerifyTokenPluginPlatform mock =
98
+ ImplementsVerifyTokenPluginPlatformUsingMockPlatformInterfaceMixin ();
99
+ VerifyTokenPluginPlatform .instance = mock;
100
+ });
101
+
102
+ test ('allows extending' , () {
103
+ VerifyTokenPluginPlatform .instance = ExtendsVerifyTokenPluginPlatform ();
104
+ });
44
105
});
45
106
}
0 commit comments