Skip to content

Commit d6a4536

Browse files
committed
Improved tests with lambda
1 parent 6736154 commit d6a4536

File tree

1 file changed

+34
-120
lines changed

1 file changed

+34
-120
lines changed

ds3-sdk/src/test/java/com/spectralogic/ds3client/Ds3Client_Test.java

Lines changed: 34 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,183 +1558,97 @@ public void getBlobsOnDs3TargetTest() throws IOException {
15581558

15591559
@Test
15601560
public void getObjectNullChannelDeprecatedConstructorTest() {
1561-
try {
1562-
new GetObjectRequest("BucketName", "ObjectName", null);
1563-
fail();
1564-
} catch (final NullPointerException e) {
1565-
assertThat(e.getMessage(), is("Channel may not be null."));
1566-
} catch (final IllegalArgumentException e) {
1567-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1568-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'channel' of com/spectralogic/ds3client/commands/GetObjectRequest.<init> must not be null"));
1569-
}
1561+
testNonnullStreamChannelExceptions("Channel",
1562+
() -> new GetObjectRequest("BucketName", "ObjectName", null));
15701563
}
15711564

15721565
@Test
15731566
public void getObjectNullChannelUuidConstructorTest() {
1574-
try {
1575-
new GetObjectRequest("BucketName", "ObjectName", null, UUID.randomUUID(), 0);
1576-
fail();
1577-
} catch (final NullPointerException e) {
1578-
assertThat(e.getMessage(), is("Channel may not be null."));
1579-
} catch (final IllegalArgumentException e) {
1580-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1581-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'channel' of com/spectralogic/ds3client/commands/GetObjectRequest.<init> must not be null"));
1582-
}
1567+
testNonnullStreamChannelExceptions("Channel",
1568+
() -> new GetObjectRequest("BucketName", "ObjectName", null, UUID.randomUUID(), 0));
15831569
}
15841570

15851571
@Test
15861572
public void getObjectNullChannelStringConstructorTest() {
1587-
try {
1588-
new GetObjectRequest("BucketName", "ObjectName", null, "JobId", 0);
1589-
fail();
1590-
} catch (final NullPointerException e) {
1591-
assertThat(e.getMessage(), is("Channel may not be null."));
1592-
} catch (final IllegalArgumentException e) {
1593-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1594-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'channel' of com/spectralogic/ds3client/commands/GetObjectRequest.<init> must not be null"));
1595-
}
1573+
testNonnullStreamChannelExceptions("Channel",
1574+
() -> new GetObjectRequest("BucketName", "ObjectName", null, "JobId", 0));
15961575
}
15971576

15981577
@Test
15991578
public void getObjectNullStreamUuidConstructorTest() {
1600-
try {
1601-
new GetObjectRequest("BucketName", "ObjectName", UUID.randomUUID(), 0, null);
1602-
fail();
1603-
} catch (final NullPointerException e) {
1604-
assertThat(e.getMessage(), is("Stream may not be null."));
1605-
} catch (final IllegalArgumentException e) {
1606-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1607-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'stream' of com/spectralogic/ds3client/commands/GetObjectRequest.<init> must not be null"));
1608-
}
1579+
testNonnullStreamChannelExceptions("Stream",
1580+
() -> new GetObjectRequest("BucketName", "ObjectName", UUID.randomUUID(), 0, null));
16091581
}
16101582

16111583
@Test
16121584
public void getObjectNullStreamStringConstructorTest() {
1613-
try {
1614-
new GetObjectRequest("BucketName", "ObjectName", "JobId", 0, null);
1615-
fail();
1616-
} catch (final NullPointerException e) {
1617-
assertThat(e.getMessage(), is("Stream may not be null."));
1618-
} catch (final IllegalArgumentException e) {
1619-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1620-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'stream' of com/spectralogic/ds3client/commands/GetObjectRequest.<init> must not be null"));
1621-
}
1585+
testNonnullStreamChannelExceptions("Stream",
1586+
() -> new GetObjectRequest("BucketName", "ObjectName", "JobId", 0, null));
16221587
}
16231588

16241589
@Test
16251590
public void putObjectDeprecatedConstructorTest() {
1626-
try {
1627-
new PutObjectRequest("BucketName", "ObjectName", null, 0);
1628-
fail();
1629-
} catch (final NullPointerException e) {
1630-
assertThat(e.getMessage(), is("Channel may not be null."));
1631-
} catch (final IllegalArgumentException e) {
1632-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1633-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'channel' of com/spectralogic/ds3client/commands/PutObjectRequest.<init> must not be null"));
1634-
}
1591+
testNonnullStreamChannelExceptions("Channel",
1592+
() -> new PutObjectRequest("BucketName", "ObjectName", null, 0));
16351593
}
16361594

16371595
@Test
16381596
public void putObjectNullChannelUuidConstructorTest() {
1639-
try {
1640-
new PutObjectRequest("BucketName", "ObjectName", null, UUID.randomUUID(),0, 0);
1641-
fail();
1642-
} catch (final NullPointerException e) {
1643-
assertThat(e.getMessage(), is("Channel may not be null."));
1644-
} catch (final IllegalArgumentException e) {
1645-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1646-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'channel' of com/spectralogic/ds3client/commands/PutObjectRequest.<init> must not be null"));
1647-
}
1597+
testNonnullStreamChannelExceptions("Channel",
1598+
() -> new PutObjectRequest("BucketName", "ObjectName", null, UUID.randomUUID(),0, 0));
16481599
}
16491600

16501601
@Test
16511602
public void putObjectNullChannelStringConstructorTest() {
1652-
try {
1653-
new PutObjectRequest("BucketName", "ObjectName", null, "JobId",0, 0);
1654-
fail();
1655-
} catch (final NullPointerException e) {
1656-
assertThat(e.getMessage(), is("Channel may not be null."));
1657-
} catch (final IllegalArgumentException e) {
1658-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1659-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'channel' of com/spectralogic/ds3client/commands/PutObjectRequest.<init> must not be null"));
1660-
}
1603+
testNonnullStreamChannelExceptions("Channel",
1604+
() -> new PutObjectRequest("BucketName", "ObjectName", null, "JobId",0, 0));
16611605
}
16621606

16631607
@Test
16641608
public void putObjectNullStreamUuidConstructorTest() {
1665-
try {
1666-
new PutObjectRequest("BucketName", "ObjectName", UUID.randomUUID(), 0, 0, null);
1667-
fail();
1668-
} catch (final NullPointerException e) {
1669-
assertThat(e.getMessage(), is("Stream may not be null."));
1670-
} catch (final IllegalArgumentException e) {
1671-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1672-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'stream' of com/spectralogic/ds3client/commands/PutObjectRequest.<init> must not be null"));
1673-
}
1609+
testNonnullStreamChannelExceptions("Stream",
1610+
() -> new PutObjectRequest("BucketName", "ObjectName", UUID.randomUUID(), 0, 0, null));
16741611
}
16751612

16761613
@Test
16771614
public void putObjectNullStreamStringConstructorTest() {
1678-
try {
1679-
new PutObjectRequest("BucketName", "ObjectName", "JobId", 0, 0, null);
1680-
fail();
1681-
} catch (final NullPointerException e) {
1682-
assertThat(e.getMessage(), is("Stream may not be null."));
1683-
} catch (final IllegalArgumentException e) {
1684-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1685-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'stream' of com/spectralogic/ds3client/commands/PutObjectRequest.<init> must not be null"));
1686-
}
1615+
testNonnullStreamChannelExceptions("Stream",
1616+
() -> new PutObjectRequest("BucketName", "ObjectName", "JobId", 0, 0, null));
16871617
}
16881618

16891619
@Test
16901620
public void putMultiPartUploadNullChannelUuidConstructorTest() {
1691-
try {
1692-
new PutMultiPartUploadPartRequest("BucketName", "ObjectName", null, 0, 0, UUID.randomUUID());
1693-
fail();
1694-
} catch (final NullPointerException e) {
1695-
assertThat(e.getMessage(), is("Channel may not be null."));
1696-
} catch (final IllegalArgumentException e) {
1697-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1698-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'channel' of com/spectralogic/ds3client/commands/PutMultiPartUploadPartRequest.<init> must not be null"));
1699-
}
1621+
testNonnullStreamChannelExceptions("Channel",
1622+
() -> new PutMultiPartUploadPartRequest("BucketName", "ObjectName", null, 0, 0, UUID.randomUUID()));
17001623
}
17011624

17021625
@Test
17031626
public void putMultiPartUploadNullChannelStringConstructorTest() {
1704-
try {
1705-
new PutMultiPartUploadPartRequest("BucketName", "ObjectName", null, 0, 0, "UploadId");
1706-
fail();
1707-
} catch (final NullPointerException e) {
1708-
assertThat(e.getMessage(), is("Channel may not be null."));
1709-
} catch (final IllegalArgumentException e) {
1710-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1711-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'channel' of com/spectralogic/ds3client/commands/PutMultiPartUploadPartRequest.<init> must not be null"));
1712-
}
1627+
testNonnullStreamChannelExceptions("Channel",
1628+
() -> new PutMultiPartUploadPartRequest("BucketName", "ObjectName", null, 0, 0, "UploadId"));
17131629
}
17141630

17151631
@Test
17161632
public void putMultiPartUploadNullStreamUuidConstructorTest() {
1717-
try {
1718-
new PutMultiPartUploadPartRequest("BucketName", "ObjectName", 0, 0, null, UUID.randomUUID());
1719-
fail();
1720-
} catch (final NullPointerException e) {
1721-
assertThat(e.getMessage(), is("Stream may not be null."));
1722-
} catch (final IllegalArgumentException e) {
1723-
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1724-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'stream' of com/spectralogic/ds3client/commands/PutMultiPartUploadPartRequest.<init> must not be null"));
1725-
}
1633+
testNonnullStreamChannelExceptions("Stream",
1634+
() -> new PutMultiPartUploadPartRequest("BucketName", "ObjectName", 0, 0, null, UUID.randomUUID()));
17261635
}
17271636

17281637
@Test
17291638
public void putMultiPartUploadNullStreamStringConstructorTest() {
1639+
testNonnullStreamChannelExceptions("Stream",
1640+
() -> new PutMultiPartUploadPartRequest("BucketName", "ObjectName", 0, 0, null, "UploadId"));
1641+
}
1642+
1643+
private void testNonnullStreamChannelExceptions(final String paramName, final Runnable runnable) {
17301644
try {
1731-
new PutMultiPartUploadPartRequest("BucketName", "ObjectName", 0, 0, null, "UploadId");
1645+
runnable.run();
17321646
fail();
17331647
} catch (final NullPointerException e) {
1734-
assertThat(e.getMessage(), is("Stream may not be null."));
1648+
assertThat(e.getMessage(), is(paramName + " may not be null."));
17351649
} catch (final IllegalArgumentException e) {
17361650
// IntelliJ IDEA throws an IllegalArgumentException if parameters are annotated as non-null are passed null values
1737-
assertThat(e.getMessage(), is("Argument for @Nonnull parameter 'stream' of com/spectralogic/ds3client/commands/PutMultiPartUploadPartRequest.<init> must not be null"));
1651+
assertThat(e.getMessage(), startsWith("Argument for @Nonnull parameter '" + paramName.toLowerCase() + "'"));
17381652
}
17391653
}
17401654
}

0 commit comments

Comments
 (0)