Skip to content

Commit 290471f

Browse files
committed
Simplified assertions in tests
1 parent dd12890 commit 290471f

2 files changed

Lines changed: 21 additions & 25 deletions

File tree

src/test/java/org/aarboard/nextcloud/api/TestConfigConnector.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,9 @@
1616
*/
1717
package org.aarboard.nextcloud.api;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertFalse;
2119
import static org.junit.Assert.assertNotNull;
22-
import static org.junit.Assert.assertTrue;
2320

24-
import java.io.ByteArrayInputStream;
25-
import java.io.InputStream;
26-
import java.util.Collection;
2721
import java.util.List;
28-
29-
import org.aarboard.nextcloud.api.provisioning.User;
30-
import org.aarboard.nextcloud.api.provisioning.UserData;
31-
import org.junit.AfterClass;
32-
import org.junit.Before;
3322
import org.junit.FixMethodOrder;
3423
import org.junit.Test;
3524
import org.junit.runners.MethodSorters;
@@ -47,7 +36,7 @@ public void t01_testGetConfigApps() {
4736
if (_nc != null)
4837
{
4938
List<String> apps = _nc.getAppConfigApps();
50-
assertTrue(apps != null);
39+
assertNotNull(apps);
5140
}
5241
}
5342

@@ -57,7 +46,7 @@ public void t02_testGetConfigAppsFiles() {
5746
if (_nc != null)
5847
{
5948
List<String> appKeys = _nc.getAppConfigAppKeys("files");
60-
assertTrue(appKeys != null);
49+
assertNotNull(appKeys);
6150
}
6251
}
6352

@@ -67,7 +56,7 @@ public void t03_testGetConfigAppsFilesVersion() {
6756
if (_nc != null)
6857
{
6958
String version = _nc.getAppConfigAppKeyValue("files", "installed_version");
70-
assertTrue(version != null);
59+
assertNotNull(version);
7160
}
7261
}
7362
}

src/test/java/org/aarboard/nextcloud/api/TestFiles.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.aarboard.nextcloud.api;
1818

19+
import static org.junit.Assert.assertEquals;
1920
import static org.junit.Assert.assertFalse;
2021
import static org.junit.Assert.assertTrue;
2122

@@ -26,6 +27,8 @@
2627
import org.aarboard.nextcloud.api.webdav.ResourceProperties;
2728
import org.junit.Assert;
2829
import static org.junit.Assert.assertNotNull;
30+
import static org.junit.Assert.fail;
31+
2932
import org.junit.FixMethodOrder;
3033
import org.junit.Test;
3134
import org.junit.runners.MethodSorters;
@@ -257,11 +260,13 @@ public void t27_99_testFileProperties() {
257260
try
258261
{
259262
_nc.getProperties(TESTFILE2+"-not-existing", false);
260-
assertFalse("Resource should throw 404 error", true);
263+
fail("Resource should throw 404 error");
261264
}
262265
catch (Exception ex)
263266
{
264-
assertTrue("com.github.sardine.impl.SardineException: status code: 404, reason phrase: Unexpected response (404 Not Found)".equals(ex.getMessage()));
267+
assertEquals(
268+
"com.github.sardine.impl.SardineException: status code: 404, reason phrase: Unexpected response (404 Not Found)",
269+
ex.getMessage());
265270
}
266271
}
267272
}
@@ -280,7 +285,8 @@ public void t28_3_testDowloadFile() throws IOException {
280285
nCount++;
281286
}
282287
is.close();
283-
assertTrue("Downloaded content size does not match", nCount == TEST3_FILE_CONTENT.length());
288+
assertEquals("Downloaded content size does not match", nCount,
289+
TEST3_FILE_CONTENT.length());
284290
}
285291
}
286292

@@ -292,11 +298,12 @@ public void t29_3_testDowloadFile() throws IOException {
292298
File of= new File(System.getProperty("java.io.tmpdir")+File.separator+TESTFILE1);
293299
if (_nc.downloadFile(TESTFILE1, of.getParent()))
294300
{
295-
assertTrue("Downloaded content size does not match", of.length() == TEST1_FILE_CONTENT.length());
301+
assertEquals("Downloaded content size does not match", of.length(),
302+
TEST1_FILE_CONTENT.length());
296303
}
297304
else
298305
{
299-
assertTrue("Downloaded file failed", false);
306+
fail("Downloaded file failed");
300307
}
301308
if (of.exists())
302309
{
@@ -313,11 +320,11 @@ public void t29_3_testDowloadFile4() throws IOException {
313320
File of= new File(System.getProperty("java.io.tmpdir")+File.separator+TESTFILE4);
314321
if (_nc.downloadFile(TESTFILE4, of.getParent()))
315322
{
316-
assertTrue("Downloaded content size does not match", of.length() == 0);
323+
assertEquals("Downloaded content size does not match", 0, of.length());
317324
}
318325
else
319326
{
320-
assertTrue("Downloaded file failed", false);
327+
fail("Downloaded file failed");
321328
}
322329
if (of.exists())
323330
{
@@ -335,11 +342,11 @@ public void t29_6_testDowloadFile6() throws IOException {
335342
if (_nc.downloadFile(TESTFILE6, of.getParent()))
336343
{
337344
File srcFile= new File("src/test/resources/"+TESTFILE6);
338-
assertTrue("Downloaded content size does not match", of.length() == srcFile.length());
345+
assertEquals("Downloaded content size does not match", of.length(), srcFile.length());
339346
}
340347
else
341348
{
342-
assertTrue("Downloaded file failed", false);
349+
fail("Downloaded file failed");
343350
}
344351
if (of.exists())
345352
{
@@ -357,11 +364,11 @@ public void t29_6_testDowloadFile7() throws IOException {
357364
if (_nc.downloadFile(TESTFILE7, of.getParent()))
358365
{
359366
File srcFile= new File("src/test/resources/"+TESTFILE7);
360-
assertTrue("Downloaded content size does not match", of.length() == srcFile.length());
367+
assertEquals("Downloaded content size does not match", of.length(), srcFile.length());
361368
}
362369
else
363370
{
364-
assertTrue("Downloaded file failed", false);
371+
fail("Downloaded file failed");
365372
}
366373
if (of.exists())
367374
{

0 commit comments

Comments
 (0)