Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mqus committed Feb 15, 2020
1 parent 4bb094a commit f8541c8
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 25 deletions.
3 changes: 2 additions & 1 deletion floor/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies:
sdk: flutter

dev_dependencies:
collection: ^1.14.11
mockito: ^4.1.1
flutter_test:
sdk: flutter
Expand All @@ -28,4 +29,4 @@ dev_dependencies:
git:
url: git://github.com/tekartik/sqflite_more
ref: dart2
path: sqflite_ffi_test
path: sqflite_ffi_test
11 changes: 11 additions & 0 deletions floor/test/integration/dao/dog_dao.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:typed_data';

import 'package:floor/floor.dart';

import '../model/dog.dart';
Expand All @@ -12,4 +14,13 @@ abstract class DogDao {

@Query('SELECT * FROM dog')
Future<List<Dog>> findAllDogs();

@update
Future<void> updateDog(Dog dog);

@insert
Future<void> addDog(Dog dog);

@Query('SELECT * FROM dog WHERE picture = :pic')
Future<Dog> findDogForPicture(Uint8List pic);
}
1 change: 1 addition & 0 deletions floor/test/integration/database.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:typed_data';

import 'package:floor/floor.dart';
import 'package:path/path.dart';
Expand Down
29 changes: 29 additions & 0 deletions floor/test/integration/database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions floor/test/integration/database_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ void main() {
final actual = await personDao.findPersonById(person.id);
expect(actual, equals(updatedPerson));
});

test('insert/update dog, search by Uint8List', () async {
final person = Person(1, 'Simon');
await personDao.insertPerson(person);
final dog = Dog(1, 'Dogbert', 'Doggy', 1, Uint8List(9));
await dogDao.addDog(dog);
final updatedDog = Dog(1, 'Dogbert 2.', 'Doggy', 1, Uint8List(7));

await dogDao.updateDog(updatedDog);

final actual = await dogDao.findDogForPicture(Uint8List(7));
expect(actual, equals(updatedDog));
});
});

group('change multiple items', () {
Expand Down
4 changes: 2 additions & 2 deletions floor/test/integration/model/dog.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:typed_data';

import 'package:collection/collection.dart';
import 'package:floor/floor.dart';

import '../../test_util/list_helper.dart';
import 'person.dart';

@Entity(
Expand Down Expand Up @@ -40,7 +40,7 @@ class Dog {
id == other.id &&
name == other.name &&
nickName == other.nickName &&
ListHelper.deepEquals(picture, other.picture) &&
const ListEquality<int>().equals(picture, other.picture) &&
ownerId == other.ownerId;

@override
Expand Down
22 changes: 0 additions & 22 deletions floor/test/test_util/list_helper.dart

This file was deleted.

23 changes: 23 additions & 0 deletions floor_generator/test/processor/field_processor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,36 @@ void main() {
);
expect(actual, equals(expected));
});

test('Process Uint8List field', () async {
final fieldElement = await _generateFieldElement('''
@ColumnInfo(name : 'data', nullable:false)
final Uint8List bytes;
''');

final actual = FieldProcessor(fieldElement).process();

const name = 'bytes';
const columnName = 'data';
const isNullable = false;
const sqlType = SqlType.BLOB;
final expected = Field(
fieldElement,
name,
columnName,
isNullable,
sqlType,
);
expect(actual, equals(expected));
});
}

Future<FieldElement> _generateFieldElement(final String field) async {
final library = await resolveSource('''
library test;
import 'package:floor_annotation/floor_annotation.dart';
import 'dart:typed_data';
class Foo {
$field
Expand Down

0 comments on commit f8541c8

Please sign in to comment.