瀏覽代碼

Added test for deleteUser function

master
BinHong Lee 7 年之前
父節點
當前提交
82d80e43f9
共有 2 個檔案被更改,包括 19 行新增6 行删除
  1. +12
    -5
      src/main/kotlin/libsys/UserFactory.kt
  2. +7
    -1
      src/test/kotlin/libsys/UserFactoryTest.kt

+ 12
- 5
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)
{


+ 7
- 1
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)


Loading…
取消
儲存