diff --git a/src/main/kotlin/libsys/UserFactory.kt b/src/main/kotlin/libsys/UserFactory.kt index f491633..d2c2c24 100644 --- a/src/main/kotlin/libsys/UserFactory.kt +++ b/src/main/kotlin/libsys/UserFactory.kt @@ -147,7 +147,14 @@ class UserFactory */ fun getUser(index: Int): User { - return search(index, 0, users.size - 1) + try + { + return search(index, 0, users.size - 1) + } + catch (e: Exception) + { + throw NullPointerException() + } } /** @@ -186,11 +193,11 @@ class UserFactory } } - fun deleteUser(id: Int): Boolean + fun deleteUser(user: User): Boolean { try { - return users.remove(getUser(id)) + return users.remove(user) } catch (e: Exception) { @@ -198,11 +205,11 @@ class UserFactory } } - fun deleteUser(user: User): Boolean + fun deleteUser(i: Int): Boolean { try { - return users.remove(user) + return users.remove(getUser(i)) } catch (e: Exception) { diff --git a/src/test/kotlin/libsys/UserFactoryTest.kt b/src/test/kotlin/libsys/UserFactoryTest.kt index 524e214..a982fb1 100644 --- a/src/test/kotlin/libsys/UserFactoryTest.kt +++ b/src/test/kotlin/libsys/UserFactoryTest.kt @@ -6,7 +6,8 @@ import java.io.File /** * Test Book related operations */ -class UserFactoryTest { +class UserFactoryTest +{ private var userFactory: UserFactory? = null init @@ -85,6 +86,11 @@ class UserFactoryTest { val anotherUserFactory = UserFactory("noSuchFile.json") Assert.assertEquals("Check ID of new User of non-existent import file", anotherUserFactory.newUser("Some person", 1).id, 0) + Assert.assertTrue(userFactory!!.deleteUser(0)) + Assert.assertFalse(userFactory!!.deleteUser(0)) + Assert.assertTrue(userFactory!!.deleteUser(user2)) + Assert.assertFalse(userFactory!!.deleteUser(user2)) + try { anotherUserFactory.getUser(1)