Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete unused code #286

Merged
merged 1 commit into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions floor_generator/lib/value_object/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,19 @@ import 'package:floor_generator/value_object/queryable.dart';
class View extends Queryable {
final String query;

View(ClassElement classElement, String name, List<Field> fields, this.query,
String constructor)
: super(classElement, name, fields, constructor);
View(
ClassElement classElement,
String name,
List<Field> fields,
this.query,
String constructor,
) : super(classElement, name, fields, constructor);

@nonNull
String getCreateViewStatement() {
return 'CREATE VIEW IF NOT EXISTS `$name` AS $query';
}

@nonNull
String getValueMapping() {
final keyValueList = fields.map((field) {
final columnName = field.columnName;
final attributeValue = _getAttributeValue(field.fieldElement);
return "'$columnName': $attributeValue";
}).toList();

return '<String, dynamic>{${keyValueList.join(', ')}}';
}

@nonNull
String _getAttributeValue(final FieldElement fieldElement) {
final parameterName = fieldElement.displayName;
return fieldElement.type.isDartCoreBool
? 'item.$parameterName ? 1 : 0'
: 'item.$parameterName';
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
Expand Down
56 changes: 8 additions & 48 deletions floor_generator/test/value_object/view_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:floor_generator/misc/constants.dart';
import 'package:floor_generator/value_object/view.dart';
import 'package:floor_generator/value_object/field.dart';
import 'package:floor_generator/value_object/view.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -36,59 +36,19 @@ void main() {
reset(mockDartType);
});

group('statement', () {
test('Create view statement with simple query', () {
final view = View(
mockClassElement,
'entityName',
allFields,
'select * from x',
'',
);

final actual = view.getCreateViewStatement();

final expected =
'CREATE VIEW IF NOT EXISTS `${view.name}` AS ${view.query}';
expect(actual, equals(expected));
});
});

group('Value mapping', () {
test('Create view statement with simple query', () {
final view = View(
mockClassElement,
'entityName',
[nullableField],
'select * from x',
allFields,
'SELECT * FROM x',
'',
);
const fieldElementDisplayName = 'foo';

setUp(() {
when(mockFieldElement.displayName).thenReturn(fieldElementDisplayName);
when(mockFieldElement.type).thenReturn(mockDartType);
});

test('Get value mapping', () {
when(mockDartType.isDartCoreBool).thenReturn(false);

final actual = view.getValueMapping();

final expected = '<String, dynamic>{'
"'${nullableField.columnName}': item.$fieldElementDisplayName"
'}';
expect(actual, equals(expected));
});

test('Get boolean value mapping', () {
when(mockDartType.isDartCoreBool).thenReturn(true);

final actual = view.getValueMapping();
final actual = view.getCreateViewStatement();

final expected = '<String, dynamic>{'
"'${nullableField.columnName}': item.$fieldElementDisplayName ? 1 : 0"
'}';
expect(actual, equals(expected));
});
final expected =
'CREATE VIEW IF NOT EXISTS `${view.name}` AS ${view.query}';
expect(actual, equals(expected));
});
}