1 /*
2  * Copyright (C) 2020 Damir Porobic <damir.porobic@gmx.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #include "DeleteImageOperationTests.h"
21 
22 #include "src/gui/operations/DeleteImageOperation.h"
23 #include "tests/mocks/MessageBoxServiceMock.h"
24 #include "tests/mocks/FileServiceMock.h"
25 
Execute_Should_ReturnFalse_When_MessageBoxResponseWasCancel()26 void DeleteImageOperationTests::Execute_Should_ReturnFalse_When_MessageBoxResponseWasCancel()
27 {
28 	auto path = QLatin1Literal("/la/la");
29 	auto messageBoxServiceMock = new MessageBoxServiceMock;
30 	messageBoxServiceMock->okCancel_set(false);
31 	auto fileServiceMock = new FileServiceMock;
32 	DeleteImageOperation operation(path, fileServiceMock, messageBoxServiceMock);
33 
34 	auto result = operation.execute();
35 
36 	QCOMPARE(result, false);
37 	QCOMPARE(fileServiceMock->remove_callCounter(path), 0);
38 }
39 
Execute_Should_ReturnTrue_When_MessageBoxResponseWasTrue_And_FileServiceSaveSuccessfully()40 void DeleteImageOperationTests::Execute_Should_ReturnTrue_When_MessageBoxResponseWasTrue_And_FileServiceSaveSuccessfully()
41 {
42 	auto path = QLatin1Literal("/la/la");
43 	auto messageBoxServiceMock = new MessageBoxServiceMock;
44 	messageBoxServiceMock->okCancel_set(true);
45 	auto fileServiceMock = new FileServiceMock;
46 	fileServiceMock->remove_set(true);
47 	DeleteImageOperation operation(path, fileServiceMock, messageBoxServiceMock);
48 
49 	auto result = operation.execute();
50 
51 	QCOMPARE(result, true);
52 	QCOMPARE(fileServiceMock->remove_callCounter(path), 1);
53 }
54 
Execute_Should_ReturnFalse_When_MessageBoxResponseWasTrue_And_FileServiceSaveFailed()55 void DeleteImageOperationTests::Execute_Should_ReturnFalse_When_MessageBoxResponseWasTrue_And_FileServiceSaveFailed()
56 {
57 	auto path = QLatin1Literal("/la/la");
58 	auto messageBoxServiceMock = new MessageBoxServiceMock;
59 	messageBoxServiceMock->okCancel_set(true);
60 	auto fileServiceMock = new FileServiceMock;
61 	fileServiceMock->remove_set(false);
62 	DeleteImageOperation operation(path, fileServiceMock, messageBoxServiceMock);
63 
64 	auto result = operation.execute();
65 
66 	QCOMPARE(result, false);
67 	QCOMPARE(fileServiceMock->remove_callCounter(path), 1);
68 }
69 
70 QTEST_MAIN(DeleteImageOperationTests)
71