Changeset View
Changeset View
Standalone View
Standalone View
tests/units/akonadi/akonadidatasourcerepositorytest.cpp
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 44 | { | |||
---|---|---|---|---|---|
46 | 46 | | |||
47 | // A source and its corresponding collection already existing in storage | 47 | // A source and its corresponding collection already existing in storage | ||
48 | Akonadi::Collection collection(42); | 48 | Akonadi::Collection collection(42); | ||
49 | auto source = Domain::DataSource::Ptr::create(); | 49 | auto source = Domain::DataSource::Ptr::create(); | ||
50 | 50 | | |||
51 | // A mock modify job | 51 | // A mock modify job | ||
52 | auto collectionModifyJob = new FakeJob(this); | 52 | auto collectionModifyJob = new FakeJob(this); | ||
53 | 53 | | |||
54 | // Storage mock returning the create job | | |||
55 | Utils::MockObject<Akonadi::StorageInterface> storageMock; | 54 | Utils::MockObject<Akonadi::StorageInterface> storageMock; | ||
56 | storageMock(&Akonadi::StorageInterface::updateCollection).when(collection, nullptr) | 55 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | ||
56 | QScopedPointer<Akonadi::DataSourceRepository> repository(new Akonadi::DataSourceRepository(storageMock.getInstance(), | ||||
57 | serializerMock.getInstance())); | ||||
58 | | ||||
59 | // Storage mock returning the create job | ||||
60 | storageMock(&Akonadi::StorageInterface::updateCollection).when(collection, repository.get()) | ||||
57 | .thenReturn(collectionModifyJob); | 61 | .thenReturn(collectionModifyJob); | ||
58 | 62 | | |||
59 | // Serializer mock returning the item for the project | 63 | // Serializer mock returning the item for the project | ||
60 | Utils::MockObject<Akonadi::SerializerInterface> serializerMock; | | |||
61 | serializerMock(&Akonadi::SerializerInterface::createCollectionFromDataSource).when(source).thenReturn(collection); | 64 | serializerMock(&Akonadi::SerializerInterface::createCollectionFromDataSource).when(source).thenReturn(collection); | ||
62 | 65 | | |||
63 | // WHEN | 66 | // WHEN | ||
64 | QScopedPointer<Akonadi::DataSourceRepository> repository(new Akonadi::DataSourceRepository(storageMock.getInstance(), | | |||
65 | serializerMock.getInstance())); | | |||
66 | repository->update(source)->exec(); | 67 | repository->update(source)->exec(); | ||
67 | 68 | | |||
68 | // THEN | 69 | // THEN | ||
69 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::createCollectionFromDataSource).when(source).exactly(1)); | 70 | QVERIFY(serializerMock(&Akonadi::SerializerInterface::createCollectionFromDataSource).when(source).exactly(1)); | ||
70 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateCollection).when(collection, nullptr).exactly(1)); | 71 | QVERIFY(storageMock(&Akonadi::StorageInterface::updateCollection).when(collection, repository.get()).exactly(1)); | ||
71 | } | 72 | } | ||
72 | }; | 73 | }; | ||
73 | 74 | | |||
74 | ZANSHIN_TEST_MAIN(AkonadiDataSourceRepositoryTest) | 75 | ZANSHIN_TEST_MAIN(AkonadiDataSourceRepositoryTest) | ||
75 | 76 | | |||
76 | #include "akonadidatasourcerepositorytest.moc" | 77 | #include "akonadidatasourcerepositorytest.moc" |