forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#17226 from [BEAM-14204] [Playground] Tests …
…for example repository * Improved test coverage of app states * Fixed constants in example state test * Improved test coverage, created request mocks * Fixed tests after merge * Added tests for the example repository, added GetExampleCodeResponse mock * [BEAM-14204] Changed hashCode field getters
- Loading branch information
1 parent
bb53425
commit da6acf2
Showing
13 changed files
with
802 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
...d/frontend/test/modules/editor/repository/example_repository/example_repository_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:playground/modules/examples/repositories/example_client/example_client.dart'; | ||
import 'package:playground/modules/examples/repositories/example_repository.dart'; | ||
|
||
import '../../../../pages/playground/states/mocks/request_mock.dart'; | ||
import 'example_repository_test.mocks.dart'; | ||
|
||
@GenerateMocks([ExampleClient]) | ||
void main() { | ||
late ExampleRepository repo; | ||
late ExampleClient client; | ||
|
||
setUp( | ||
() { | ||
client = MockExampleClient(); | ||
repo = ExampleRepository(client); | ||
}, | ||
); | ||
|
||
test( | ||
'Example repository getListOfExamples should return response with categories', | ||
() async { | ||
when(client.getListOfExamples(kGetListOfExamplesRequestMock)) | ||
.thenAnswer((_) async => kGetListOfExamplesResponseMock); | ||
expect( | ||
await repo.getListOfExamples(kGetListOfExamplesRequestMock), | ||
kGetListOfExamplesResponseMock.categories, | ||
); | ||
verify(client.getListOfExamples(kGetListOfExamplesRequestMock)).called(1); | ||
}, | ||
); | ||
|
||
test( | ||
'Example repository getDefaultExample should return defaultExample for chosen Sdk', | ||
() async { | ||
when(client.getDefaultExample(kGetExampleRequestMock)) | ||
.thenAnswer((_) async => kGetExampleResponseMock); | ||
expect( | ||
await repo.getDefaultExample(kGetExampleRequestMock), | ||
kGetExampleResponseMock.example, | ||
); | ||
verify(client.getDefaultExample(kGetExampleRequestMock)).called(1); | ||
}, | ||
); | ||
|
||
test( | ||
'Example repository getExampleSource should return source code for example', | ||
() async { | ||
when(client.getExampleSource(kGetExampleRequestMock)) | ||
.thenAnswer((_) async => kGetExampleCodeResponseMock); | ||
expect( | ||
await repo.getExampleSource(kGetExampleRequestMock), | ||
kGetExampleCodeResponseMock.code, | ||
); | ||
verify(client.getExampleSource(kGetExampleRequestMock)).called(1); | ||
}, | ||
); | ||
|
||
test( | ||
'Example repository getExampleOutput should return output for example', | ||
() async { | ||
when(client.getExampleOutput(kGetExampleRequestMock)) | ||
.thenAnswer((_) async => kOutputResponseMock); | ||
expect( | ||
await repo.getExampleOutput(kGetExampleRequestMock), | ||
kOutputResponseMock.output, | ||
); | ||
verify(client.getExampleOutput(kGetExampleRequestMock)).called(1); | ||
}, | ||
); | ||
|
||
test( | ||
'Example repository getExampleLogs should return logs for example', | ||
() async { | ||
when(client.getExampleLogs(kGetExampleRequestMock)) | ||
.thenAnswer((_) async => kOutputResponseMock); | ||
expect( | ||
await repo.getExampleLogs(kGetExampleRequestMock), | ||
kOutputResponseMock.output, | ||
); | ||
verify(client.getExampleLogs(kGetExampleRequestMock)).called(1); | ||
}, | ||
); | ||
|
||
test( | ||
'Example repository getExampleLogs should return logs for example', | ||
() async { | ||
when(client.getExampleGraph(kGetExampleRequestMock)) | ||
.thenAnswer((_) async => kOutputResponseMock); | ||
expect( | ||
await repo.getExampleGraph(kGetExampleRequestMock), | ||
kOutputResponseMock.output, | ||
); | ||
verify(client.getExampleGraph(kGetExampleRequestMock)).called(1); | ||
}, | ||
); | ||
|
||
test( | ||
'Example repository getExample should return ExampleModel', | ||
() async { | ||
when(client.getExample(kGetExampleRequestMock)) | ||
.thenAnswer((_) async => kGetExampleResponseMock); | ||
expect( | ||
await repo.getExample(kGetExampleRequestMock), | ||
kGetExampleResponseMock.example, | ||
); | ||
verify(client.getExample(kGetExampleRequestMock)).called(1); | ||
}, | ||
); | ||
} |
119 changes: 119 additions & 0 deletions
119
...tend/test/modules/editor/repository/example_repository/example_repository_test.mocks.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// Mocks generated by Mockito 5.1.0 from annotations | ||
// in playground/test/modules/editor/repository/example_repository/example_repository_test.dart. | ||
// Do not manually edit this file. | ||
|
||
import 'dart:async' as _i7; | ||
|
||
import 'package:mockito/mockito.dart' as _i1; | ||
import 'package:playground/modules/editor/repository/code_repository/code_client/output_response.dart' | ||
as _i5; | ||
import 'package:playground/modules/examples/repositories/example_client/example_client.dart' | ||
as _i6; | ||
import 'package:playground/modules/examples/repositories/models/get_example_code_response.dart' | ||
as _i3; | ||
import 'package:playground/modules/examples/repositories/models/get_example_request.dart' | ||
as _i9; | ||
import 'package:playground/modules/examples/repositories/models/get_example_response.dart' | ||
as _i4; | ||
import 'package:playground/modules/examples/repositories/models/get_list_of_examples_request.dart' | ||
as _i8; | ||
import 'package:playground/modules/examples/repositories/models/get_list_of_examples_response.dart' | ||
as _i2; | ||
|
||
// ignore_for_file: type=lint | ||
// ignore_for_file: avoid_redundant_argument_values | ||
// ignore_for_file: avoid_setters_without_getters | ||
// ignore_for_file: comment_references | ||
// ignore_for_file: implementation_imports | ||
// ignore_for_file: invalid_use_of_visible_for_testing_member | ||
// ignore_for_file: prefer_const_constructors | ||
// ignore_for_file: unnecessary_parenthesis | ||
// ignore_for_file: camel_case_types | ||
|
||
class _FakeGetListOfExampleResponse_0 extends _i1.Fake | ||
implements _i2.GetListOfExampleResponse {} | ||
|
||
class _FakeGetExampleCodeResponse_1 extends _i1.Fake | ||
implements _i3.GetExampleCodeResponse {} | ||
|
||
class _FakeGetExampleResponse_2 extends _i1.Fake | ||
implements _i4.GetExampleResponse {} | ||
|
||
class _FakeOutputResponse_3 extends _i1.Fake implements _i5.OutputResponse {} | ||
|
||
/// A class which mocks [ExampleClient]. | ||
/// | ||
/// See the documentation for Mockito's code generation for more information. | ||
class MockExampleClient extends _i1.Mock implements _i6.ExampleClient { | ||
MockExampleClient() { | ||
_i1.throwOnMissingStub(this); | ||
} | ||
|
||
@override | ||
_i7.Future<_i2.GetListOfExampleResponse> getListOfExamples( | ||
_i8.GetListOfExamplesRequestWrapper? request) => | ||
(super.noSuchMethod(Invocation.method(#getListOfExamples, [request]), | ||
returnValue: Future<_i2.GetListOfExampleResponse>.value( | ||
_FakeGetListOfExampleResponse_0())) | ||
as _i7.Future<_i2.GetListOfExampleResponse>); | ||
@override | ||
_i7.Future<_i3.GetExampleCodeResponse> getExampleSource( | ||
_i9.GetExampleRequestWrapper? request) => | ||
(super.noSuchMethod(Invocation.method(#getExampleSource, [request]), | ||
returnValue: Future<_i3.GetExampleCodeResponse>.value( | ||
_FakeGetExampleCodeResponse_1())) | ||
as _i7.Future<_i3.GetExampleCodeResponse>); | ||
@override | ||
_i7.Future<_i4.GetExampleResponse> getDefaultExample( | ||
_i9.GetExampleRequestWrapper? request) => | ||
(super.noSuchMethod(Invocation.method(#getDefaultExample, [request]), | ||
returnValue: Future<_i4.GetExampleResponse>.value( | ||
_FakeGetExampleResponse_2())) | ||
as _i7.Future<_i4.GetExampleResponse>); | ||
@override | ||
_i7.Future<_i4.GetExampleResponse> getExample( | ||
_i9.GetExampleRequestWrapper? request) => | ||
(super.noSuchMethod(Invocation.method(#getExample, [request]), | ||
returnValue: Future<_i4.GetExampleResponse>.value( | ||
_FakeGetExampleResponse_2())) | ||
as _i7.Future<_i4.GetExampleResponse>); | ||
@override | ||
_i7.Future<_i5.OutputResponse> getExampleOutput( | ||
_i9.GetExampleRequestWrapper? request) => | ||
(super.noSuchMethod(Invocation.method(#getExampleOutput, [request]), | ||
returnValue: | ||
Future<_i5.OutputResponse>.value(_FakeOutputResponse_3())) | ||
as _i7.Future<_i5.OutputResponse>); | ||
@override | ||
_i7.Future<_i5.OutputResponse> getExampleLogs( | ||
_i9.GetExampleRequestWrapper? request) => | ||
(super.noSuchMethod(Invocation.method(#getExampleLogs, [request]), | ||
returnValue: | ||
Future<_i5.OutputResponse>.value(_FakeOutputResponse_3())) | ||
as _i7.Future<_i5.OutputResponse>); | ||
@override | ||
_i7.Future<_i5.OutputResponse> getExampleGraph( | ||
_i9.GetExampleRequestWrapper? request) => | ||
(super.noSuchMethod(Invocation.method(#getExampleGraph, [request]), | ||
returnValue: | ||
Future<_i5.OutputResponse>.value(_FakeOutputResponse_3())) | ||
as _i7.Future<_i5.OutputResponse>); | ||
} |
Oops, something went wrong.