removed some catches, added nullpointer checks

This commit is contained in:
Dave
2015-06-28 21:32:15 +02:00
parent 64e408a67a
commit e3873ed22c

View File

@@ -70,10 +70,10 @@ public class NoUserTest {
} }
@Test @Test
public void testCreateUserFromFile() { public void testCreateUserFromFile() throws IllegalBlockSizeException, BadPaddingException, ClassNotFoundException, IOException {
NoUser user = new NoUser(); NoUser user = new NoUser();
final byte[] originalFile = user.createFile("password".toCharArray()); final byte[] originalFile = user.createFile("password".toCharArray());
byte[] file = originalFile; byte[] file = Arrays.copyOf(originalFile, originalFile.length);
byte[] hash = user.createHash(); byte[] hash = user.createHash();
String hashString = user.createHashString(); String hashString = user.createHashString();
user = null; user = null;
@@ -81,24 +81,36 @@ public class NoUserTest {
try { try {
user = NoUser.createUserFromFile(file, "wrongpassword".toCharArray()); user = NoUser.createUserFromFile(file, "wrongpassword".toCharArray());
fail("Should have thrown an error when given wrong password."); fail("Should have thrown an error when given wrong password.");
} catch (IllegalBlockSizeException e) {
fail("IllegalBlockSizeException encountered.");
} catch (BadPaddingException e) { } catch (BadPaddingException e) {
// Do nothing, correct // Do nothing, correct
} catch (ClassNotFoundException e) { }
fail("ClassNotFoundException encountered.");
} catch (IOException e) { file = Arrays.copyOf(originalFile, originalFile.length);
fail("IOException encountered."); user = NoUser.createUserFromFile(file, "password".toCharArray());
assertTrue(Arrays.equals(hash, user.createHash()));
assertEquals(hashString, user.createHashString());
file = Arrays.copyOf(originalFile, originalFile.length);
try {
NoUser.createUserFromFile(file, null);
fail("Should have thrown a NullPointerException.");
} catch (NullPointerException e) {
// Do nothing, correct
} }
try { try {
user = NoUser.createUserFromFile(file, "password".toCharArray()); NoUser.createUserFromFile(null, "password".toCharArray());
} catch (IllegalBlockSizeException | BadPaddingException | ClassNotFoundException | IOException e) { fail("Should have thrown a NullPointerException.");
fail("Encountered an error of type " + e.getClass().getSimpleName()); } catch (NullPointerException e) {
// Do nothing, correct
} }
assertTrue(Arrays.equals(hash, user.createHash())); try {
assertEquals(hashString, user.createHashString()); NoUser.createUserFromFile(null, null);
fail("Should have thrown a NullPointerException.");
} catch (NullPointerException e) {
// Do nothing, correct
}
} }
} }