Replaced all IllegalStateException with DataException in arbitrary code

This was necessary to ensure that all exceptions are caught intentionally, as otherwise it creates endless amounts of edge cases.
This commit is contained in:
CalDescent
2021-11-19 21:42:03 +00:00
parent 8cb06bf451
commit 73e609fa29
25 changed files with 209 additions and 185 deletions

View File

@@ -22,7 +22,7 @@ public class ArbitraryDataDigestTests extends Common {
}
@Test
public void testDirectoryDigest() throws IOException {
public void testDirectoryDigest() throws IOException, DataException {
Path dataPath = Paths.get("src/test/resources/arbitrary/demo1");
String expectedHash58 = "DKyMuonWKoneJqiVHgw26Vk1ytrZG9PGsE9xfBg3GKDp";

View File

@@ -18,7 +18,7 @@ public class ArbitraryDataFileTests extends Common {
}
@Test
public void testSplitAndJoin() {
public void testSplitAndJoin() throws DataException {
String dummyDataString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
ArbitraryDataFile arbitraryDataFile = new ArbitraryDataFile(dummyDataString.getBytes());
assertTrue(arbitraryDataFile.exists());
@@ -45,7 +45,7 @@ public class ArbitraryDataFileTests extends Common {
}
@Test
public void testSplitAndJoinWithLargeFiles() {
public void testSplitAndJoinWithLargeFiles() throws DataException {
int fileSize = (int) (5.5f * 1024 * 1024); // 5.5MiB
byte[] randomData = new byte[fileSize];
new Random().nextBytes(randomData); // No need for SecureRandom here

View File

@@ -148,7 +148,7 @@ public class ArbitraryDataMergeTests extends Common {
patch.create();
fail("Creating patch should fail due to matching states");
} catch (IllegalStateException expectedException) {
} catch (DataException expectedException) {
assertEquals("Current state matches previous state. Nothing to do.", expectedException.getMessage());
}

View File

@@ -234,7 +234,7 @@ public class ArbitraryDataTests extends Common {
arbitraryDataReader1a.loadSynchronously(true);
fail("Loading data with null identifier should fail due to nonexistent PUT transaction");
} catch (IllegalStateException expectedException) {
} catch (DataException expectedException) {
assertEquals(String.format("Couldn't find PUT transaction for name %s, service %s "
+ "and identifier ", name.toLowerCase(), service), expectedException.getMessage());
}
@@ -246,7 +246,7 @@ public class ArbitraryDataTests extends Common {
arbitraryDataReader1b.loadSynchronously(true);
fail("Loading data with incorrect identifier should fail due to nonexistent PUT transaction");
} catch (IllegalStateException expectedException) {
} catch (DataException expectedException) {
assertEquals(String.format("Couldn't find PUT transaction for name %s, service %s "
+ "and identifier %s", name.toLowerCase(), service, differentIdentifier), expectedException.getMessage());
}
@@ -321,7 +321,7 @@ public class ArbitraryDataTests extends Common {
arbitraryDataReader1c.loadSynchronously(true);
fail("Loading data with incorrect identifier should fail due to nonexistent PUT transaction");
} catch (IllegalStateException expectedException) {
} catch (DataException expectedException) {
assertEquals(String.format("Couldn't find PUT transaction for name %s, service %s "
+ "and identifier %s", name.toLowerCase(), service, differentIdentifier), expectedException.getMessage());
}