From 02775409db4b6eabea483fc8af89bb6ac0d37049 Mon Sep 17 00:00:00 2001 From: Mircea MATEI Date: Thu, 14 Mar 2019 03:21:35 +0200 Subject: [PATCH] #8. Preparing tests for the entity writer --- .../flutter_sqlite_m8_generator_test.dart | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/flutter_sqlite_m8_generator_test.dart b/src/test/flutter_sqlite_m8_generator_test.dart index 3ee8ca4..454d6d7 100644 --- a/src/test/flutter_sqlite_m8_generator_test.dart +++ b/src/test/flutter_sqlite_m8_generator_test.dart @@ -1,3 +1,5 @@ +import 'package:flutter_orm_m8/flutter_orm_m8.dart'; +import 'package:flutter_sqlite_m8_generator/generator/core.dart'; import 'package:flutter_sqlite_m8_generator/orm_m8_generator.dart'; import 'package:source_gen/source_gen.dart'; import 'package:test/test.dart'; @@ -17,5 +19,30 @@ void main() async { final expected = "/*\nInstance of 'EntityWriter'\n*/"; expect(output, expected); }); + + test('Missing test annotation', () async { + expect( + () => getEmittedEntityForAnnotation( + "this_test_annotation_does_not_exists"), + throwsA(const TypeMatcher())); + }); + + test('OK test annotation', () async { + var e = getEmittedEntityForAnnotation("my_health_entries_table"); + expect(e.entityName, "my_health_entries_table"); + }); }); } + +EmittedEntity getEmittedEntityForAnnotation(String testAnnotation) { + var annotatedElement = _library + .annotatedWith(TypeChecker.fromRuntime(DataTable)) + .firstWhere((f) => + f.annotation.objectValue.getField('name').toStringValue() == + testAnnotation); + + var entityName = + annotatedElement.annotation.objectValue.getField('name').toStringValue(); + + return ModelParser(annotatedElement.element, entityName).getEmittedEntity(); +}