-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathHybridFileParcelableTest.java
More file actions
221 lines (196 loc) · 7.37 KB
/
HybridFileParcelableTest.java
File metadata and controls
221 lines (196 loc) · 7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* Copyright (C) 2014-2026 Arpit Khurana <arpitkh96@gmail.com>, Vishal Nehra <vishalmeham2@gmail.com>,
* Emmanuel Messulam<emmanuelbendavid@gmail.com>, Raymond Lai <airwave209gt at gmail.com> and Contributors.
*
* This file is part of Amaze File Manager.
*
* Amaze File Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.amaze.filemanager.filesystem;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import com.amaze.filemanager.fileoperations.filesystem.OpenMode;
import android.os.Parcel;
/** Created by Rustam Khadipash on 29/3/2018. */
public class HybridFileParcelableTest {
private HybridFileParcelable filePath;
private HybridFileParcelable directory;
private HybridFileParcelable file;
@Before
public void setUp() {
filePath = new HybridFileParcelable("/storage/sdcard0/Test1/Test1.txt");
directory = new HybridFileParcelable("/storage/sdcard0/Test2", "rw", 123456, 654321, true);
file =
new HybridFileParcelable("/storage/sdcard0/Test3/Test3.txt", "rw", 123456, 654321, false);
}
/** Purpose: Get name of a file / directory Input: no Expected: return file / directory's name */
@Test
public void getName() {
assertEquals("Test1.txt", filePath.getName());
assertEquals("Test2", directory.getName());
assertEquals("Test3.txt", file.getName());
}
/**
* Purpose: Change name of a file / directory Input: setName newName Expected: File / directory's
* name is changed
*/
@Test
public void setName() {
filePath.setName("Tset1.txt");
assertEquals("Tset1.txt", filePath.getName());
directory.setName("Tset2");
assertEquals("Tset2", directory.getName());
file.setName("Tset3.txt");
assertEquals("Tset3.txt", file.getName());
}
/**
* Purpose: Get open mode of a file / directory Input: no Expected: return OpenMode.FILE
*
* <p>All files and directories in this class have open mode set as OpenMode.FILE
*/
@Test
public void getMode() {
assertEquals(OpenMode.FILE, filePath.getMode());
assertEquals(OpenMode.FILE, directory.getMode());
assertEquals(OpenMode.FILE, file.getMode());
}
/** Purpose: Get link to a file / directory Input: no Expected: return empty string */
@Test
public void getLink() {
assertEquals("", filePath.getLink());
assertEquals("", directory.getLink());
assertEquals("", file.getLink());
}
/**
* Purpose: Set link to a file / directory Input: setLink newLink Expected: File / directory's
* link is changed
*/
@Test
public void setLink() {
filePath.setLink("abc");
assertEquals("abc", filePath.getLink());
directory.setLink("def");
assertEquals("def", directory.getLink());
file.setLink("ghi");
assertEquals("ghi", file.getLink());
}
/** Purpose: Get creation date of a file / directory Input: no Expected: return date */
@Test
public void getDate() {
assertEquals(0, filePath.getDate());
assertEquals(123456, directory.getDate());
assertEquals(123456, file.getDate());
}
/**
* Purpose: Change creation date of a file / directory Input: setDate newDate Expected: File /
* directory's creation date is changed
*/
@Test
public void setDate() {
filePath.setDate(746352);
assertEquals(746352, filePath.getDate());
directory.setDate(474587);
assertEquals(474587, directory.getDate());
file.setDate(3573335);
assertEquals(3573335, file.getDate());
}
/** Purpose: Get size of a file / directory Input: no Expected: return size */
@Test
public void getSize() {
assertEquals(0, filePath.getSize());
assertEquals(654321, directory.getSize());
assertEquals(654321, file.getSize());
}
/**
* Purpose: Change size of a file / directory Input: setSize newSize Expected: File / directory's
* size is changed
*/
@Test
public void setSize() {
filePath.setSize(3534546);
assertEquals(3534546, filePath.getSize());
directory.setSize(1745534);
assertEquals(1745534, directory.getSize());
file.setSize(7546543);
assertEquals(7546543, file.getSize());
}
/** Purpose: Check whether it is a file or directory Input: no Expected: return directory */
@Test
public void isDirectory() {
assertEquals(false, filePath.isDirectory());
assertEquals(true, directory.isDirectory());
assertEquals(false, file.isDirectory());
}
/**
* Purpose: Change type to file / directory Input: setDirectory isDirectory Expected: File /
* directory's type is changed
*/
@Test
public void setDirectory() {
filePath.setDirectory(true);
assertEquals(true, filePath.isDirectory());
directory.setDirectory(false);
assertEquals(false, directory.isDirectory());
file.setDirectory(true);
assertEquals(true, file.isDirectory());
}
/** Purpose: Get path to a file / directory Input: no Expected: return path */
@Test
public void getPath() {
assertEquals("/storage/sdcard0/Test1/Test1.txt", filePath.getPath());
assertEquals("/storage/sdcard0/Test2", directory.getPath());
assertEquals("/storage/sdcard0/Test3/Test3.txt", file.getPath());
}
/** Purpose: Get file / directory's permissions Input: no Expected: return permissions */
@Test
public void getPermission() {
assertEquals(null, filePath.getPermission());
assertEquals("rw", directory.getPermission());
assertEquals("rw", file.getPermission());
}
/**
* Purpose: Change permissions of a file / directory Input: setPermission newPermission Expected:
* File / directory's permissions are changed
*/
@Test
public void setPermission() {
filePath.setPermission("rwx");
assertEquals("rwx", filePath.getPermission());
directory.setPermission("rwx");
assertEquals("rwx", directory.getPermission());
file.setPermission("rwx");
assertEquals("rwx", file.getPermission());
}
/**
* Purpose: Write an object into a parcel, send it through an intent and read the object from the
* parcel Input: writeToParcel parcel object Expected: The parcel can be sent and the object can
* be extracted from the parcel
*/
@Test
public void writeToParcel() {
Parcel parcel = Parcel.obtain();
file.writeToParcel(parcel, file.describeContents());
parcel.setDataPosition(0);
HybridFileParcelable createdFromParcel = HybridFileParcelable.CREATOR.createFromParcel(parcel);
assertEquals(file.getDate(), createdFromParcel.getDate());
assertEquals(file.getLink(), createdFromParcel.getLink());
assertEquals(file.getMode(), createdFromParcel.getMode());
assertEquals(file.getName(), createdFromParcel.getName());
assertEquals(file.getPath(), createdFromParcel.getPath());
assertEquals(file.getPermission(), createdFromParcel.getPermission());
assertEquals(file.getSize(), createdFromParcel.getSize());
assertEquals(file.isDirectory(), createdFromParcel.isDirectory());
}
}