Skip to content

Commit d0d3a7b

Browse files
committed
changed tests
1 parent ba39f03 commit d0d3a7b

File tree

4 files changed

+74
-39
lines changed

4 files changed

+74
-39
lines changed

integration_tests/test/empty_method_mapper/empty_method_mapper.dart

Lines changed: 0 additions & 21 deletions
This file was deleted.

integration_tests/test/empty_method_mapper/empty_method_mapper_test.dart

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
import 'package:test/test.dart';
3+
4+
import 'simple_mapper.dart';
5+
6+
void main() {
7+
group('Field Mapper', () {
8+
9+
test('Should be instantiated', () {
10+
expect(SimpleMapper.INSTANCE, isNotNull);
11+
});
12+
13+
test('Should return null when input is null', () {
14+
expect(SimpleMapper.INSTANCE.modelToDto(null), isNull);
15+
});
16+
17+
test('Should not return null when input is not null', () {
18+
final model = Model()..field = 'test';
19+
expect(SimpleMapper.INSTANCE.modelToDto(model), isNotNull);
20+
});
21+
22+
test('Should assign field when input has same field name and type', () {
23+
final model = Model()..field = 'test';
24+
final mappedResult = SimpleMapper.INSTANCE.modelToDto(model);
25+
expect(mappedResult.field, equals('test'));
26+
});
27+
28+
test('Should not assign field when input has not same field name', () {
29+
final model = DifferentModel()..differentField = 'test';
30+
final mappedResult = SimpleMapper.INSTANCE.differentModelToDto(model);
31+
expect(mappedResult.field, isNull);
32+
});
33+
34+
test('Should not assign field when input has different type', () {
35+
final model = DifferentFieldTypeModel()..field = 4;
36+
final mappedResult = SimpleMapper.INSTANCE.differentFieldTypeModelToDto(model);
37+
expect(mappedResult.field, isNull);
38+
});
39+
40+
});
41+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
import 'package:dartstruct/dartstruct.dart';
3+
4+
part 'simple_mapper.g.dart';
5+
6+
class Model {
7+
String field;
8+
}
9+
10+
class DifferentModel {
11+
String differentField;
12+
}
13+
14+
class DifferentFieldTypeModel {
15+
int field;
16+
}
17+
18+
class Dto {
19+
String field;
20+
}
21+
22+
@Mapper()
23+
abstract class SimpleMapper {
24+
25+
static SimpleMapper get INSTANCE => SimpleMapperImpl();
26+
27+
Dto modelToDto(Model model);
28+
29+
Dto differentModelToDto(DifferentModel model);
30+
31+
Dto differentFieldTypeModelToDto(DifferentFieldTypeModel model);
32+
33+
}

0 commit comments

Comments
 (0)