Skip to content

Commit b543b4f

Browse files
authored
Merge pull request #1889 from User253489/master
Fix issues in comments and return values.
2 parents 706dcf5 + 5efced2 commit b543b4f

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

src/main/java/org/testng/FileAssert.java

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.io.IOException;
55

66
/**
7-
* Assertion tool for File centric assertions. Conceptually this is an extension of {@link Assert}
7+
* Assertion tool for File centric assertions. Conceptually, this is an extension of {@link Assert}.
88
* Presents assertion methods with a more natural parameter order. The order is always
99
* <B>actualValue</B>, <B>expectedValue</B> [, message].
1010
*
@@ -13,14 +13,14 @@
1313
*/
1414
public class FileAssert {
1515

16-
/** Protect constructor since it is a static only class */
16+
/** Protect this constructor since it is a static only class. */
1717
private FileAssert() {
18-
// hide constructor
18+
// Hide this constructor.
1919
}
2020

2121
/**
22-
* Asserts that a {@code tstvalue} is a proper directory. If it isn't, an AssertionError, with the
23-
* given message, is thrown.
22+
* Asserts that a {@code tstvalue} is a proper directory. If it isn't, an AssertionError with the
23+
* given message is thrown.
2424
*
2525
* @param tstvalue the file to evaluate
2626
* @param message the assertion error message
@@ -42,8 +42,8 @@ public static void assertDirectory(File tstvalue) {
4242
}
4343

4444
/**
45-
* Asserts that a {@code tstvalue} is a proper file. If it isn't, an AssertionError, with the
46-
* given message, is thrown.
45+
* Asserts that a {@code tstvalue} is a proper file. If it isn't, an AssertionError with the
46+
* given message is thrown.
4747
*
4848
* @param tstvalue the file to evaluate
4949
* @param message the assertion error message
@@ -67,7 +67,7 @@ public static void assertFile(File tstvalue) {
6767

6868
/**
6969
* Asserts that a {@code tstvalue} is a file of exactly {@code expected} characters or a directory
70-
* of exactly {@code expected} entries. If it isn't, an AssertionError, with the given message, is
70+
* of exactly {@code expected} entries. If it isn't, an AssertionError with the given message is
7171
* thrown.
7272
*
7373
* @param tstvalue the file to evaluate
@@ -92,8 +92,8 @@ public static void assertLength(File tstvalue, long expected) {
9292

9393
/**
9494
* Asserts that a {@code tstvalue} is a file of at least {@code expected} characters or a
95-
* directory of at least {@code expected} entries. If it isn't, an AssertionError, with the given
96-
* message, is thrown.
95+
* directory of at least {@code expected} entries. If it isn't, an AssertionError with the given
96+
* message is thrown.
9797
*
9898
* @param tstvalue the file to evaluate
9999
* @param message the assertion error message
@@ -118,7 +118,7 @@ public static void assertMinLength(File tstvalue, long expected) {
118118

119119
/**
120120
* Asserts that a {@code tstvalue} is a file of at most {@code expected} characters or a directory
121-
* of at most {@code expected} entries. If it isn't, an AssertionError, with the given message, is
121+
* of at most {@code expected} entries. If it isn't, an AssertionError with the given message is
122122
* thrown.
123123
*
124124
* @param tstvalue the file to evaluate
@@ -143,8 +143,8 @@ public static void assertMaxLength(File tstvalue, long expected) {
143143
}
144144

145145
/**
146-
* Asserts that a {@code tstvalue} is readable. If it isn't, an AssertionError, with the given
147-
* message, is thrown.
146+
* Asserts that a {@code tstvalue} is readable. If it isn't, an AssertionError with the given
147+
* message is thrown.
148148
*
149149
* @param tstvalue the file to evaluate
150150
* @param message the assertion error message
@@ -167,8 +167,8 @@ public static void assertReadable(File tstvalue) {
167167
}
168168

169169
/**
170-
* Asserts that a {@code tstvalue} is writeable. If it isn't, an AssertionError, with the given
171-
* message, is thrown.
170+
* Asserts that a {@code tstvalue} is writeable. If it isn't, an AssertionError with the given
171+
* message is thrown.
172172
*
173173
* @param tstvalue the file to evaluate
174174
* @param message the assertion error message
@@ -191,8 +191,8 @@ public static void assertWriteable(File tstvalue) {
191191
}
192192

193193
/**
194-
* Asserts that a {@code tstvalue} is readable and writeable. If it isn't, an AssertionError, with
195-
* the given message, is thrown.
194+
* Asserts that a {@code tstvalue} is readable and writeable. If it isn't, an AssertionError with
195+
* the given message is thrown.
196196
*
197197
* @param tstvalue the file to evaluate
198198
* @param message the assertion error message
@@ -241,7 +241,7 @@ public static void fail() {
241241
fail(null);
242242
}
243243

244-
/** Formats failure for file assertions */
244+
/** Formats failure for file assertions. */
245245
private static void failFile(File path, String actual, String expected, String message) {
246246
String formatted = "";
247247
if (message != null) {
@@ -287,34 +287,37 @@ private static void failSecurity(
287287
private static String fileType(File path) {
288288
try {
289289
if (!path.exists()) {
290-
return "Non existant";
291-
} else if (path.isDirectory()) {
290+
return "Nonexistent";
291+
}
292+
if (path.isDirectory()) {
292293
return "Directory";
293-
} else if (path.isFile()) {
294+
}
295+
if (path.isFile()) {
294296
return "File";
295-
} else {
296-
return "Special File";
297297
}
298+
return "Special File";
298299
} catch (SecurityException e) {
299300
return "Unauthorized";
300301
}
301302
}
302303

303-
/** String representation of what sort of file {@code path} is. */
304+
/** String representation of read and write permissions of {@code path}. */
304305
private static String fileAccess(File path) {
305306
try {
306307
if (!path.exists()) {
307-
return "Non existant";
308-
} else if (path.canWrite() && path.canRead()) {
309-
return "Read/Write Access";
310-
} else if (path.canRead()) {
311-
return "Read only Access";
312-
} else if (path.canWrite()) {
313-
return "Write only Access";
314-
} else {
315-
return "No Access";
308+
return "Nonexistent";
309+
}
310+
if (path.canRead() && path.canWrite()) {
311+
return "Read and Write Access";
312+
}
313+
if (path.canRead()) {
314+
return "Read but not Write Access";
316315
}
317-
} catch (SecurityException e) {
316+
if (path.canWrite()) {
317+
return "Write but not Read Access";
318+
}
319+
return "Neither Read nor Write Access";
320+
} catch (SecurityException e) {
318321
return "Unauthorized";
319322
}
320323
}

0 commit comments

Comments
 (0)