Compare commits

..

No commits in common. 'ec33ebbea4fff7c4d2b50ae704b5471658d4cfd8' and 'ad5ae952ac6dd10d178868a293b6af9af80dfa1a' have entirely different histories.

@ -108,9 +108,7 @@ class ServicesStub : IServices {
val userStub = services.getAllUsers()
val nbUser = userStub.size
if(username == "" || email == "" || passwd == ""){
return false
}
if(!isUsernameExist(username) && !isEmailExist(email)){
val user = User(nbUser,username, email, date,randomImage(), passwordhash, SrcLanguage.vo)
users.add(user)//ajout au stub
@ -144,18 +142,15 @@ class ServicesStub : IServices {
override fun getSomeQuotes(nb: Int, page: Int): MutableList<Quote> {
var nbQuote = nb
var nbPage = page
if(nb < 0) nbQuote = 1
if(nbPage < 0) nbPage = 1
val fromIndex = (nbPage - 1) * nbQuote
val toIndex = minOf(nbPage * nbQuote, quotes.size)
val fromIndex = (page - 1) * nbQuote
val toIndex = minOf(page * nbQuote, quotes.size)
if (fromIndex >= quotes.size) return mutableListOf()
return quotes.subList(fromIndex, toIndex).toMutableList()
}
override fun isFavorite(idQuote: Int, idUser: Int): Boolean {
val user = getUserById(idUser) ?: return false
val quote = getFavorite(user)

@ -4,24 +4,16 @@ import org.junit.Assert.assertEquals
import org.junit.Test
import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.data.services.ServicesStub
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
class UnitTestQuote {
private val services : IServices = ServicesStub()
@Test
fun testGetQuote_OK(){
fun testGetQuote(){
val quote = services.getQuote(1)
assertEquals("All we have to decide is what to do with the time that is given us.",quote?.content)
}
@Test
fun testGetQuote_Fake(){
val quote = services.getQuote(-1)
assertEquals(null,quote?.content)
}
@Test
fun testGetSomeQuote_OK(){
val quote = services.getSomeQuotes(4,1)
@ -29,19 +21,13 @@ class UnitTestQuote {
}
@Test
fun testGetSomeQuoteIndexNegatif(){
fun testGetSomeQuoteNegatif(){
val quote = services.getSomeQuotes(-1,1)
assertEquals(1,quote.size)
}
@Test
fun testGetSomeQuotePageNegatif(){
val quote = services.getSomeQuotes(1,-1)
assertEquals(1,quote.size)
}
@Test
fun testGetSomeQuoteIndex0(){
fun testGetSomeQuote0(){
val quote = services.getSomeQuotes(0,1)
assertEquals(0,quote.size)
}
@ -140,22 +126,5 @@ class UnitTestQuote {
assertEquals(0,quote.size)
}
@Test
fun testIsFavorite_OK(){
assertTrue(services.isFavorite(1,10))
}
@Test
fun testIsFavorite_FakeQuote(){
assertFalse(services.isFavorite(-1,10))
}
@Test
fun testIsFavorite_FakeUser(){
assertFalse(services.isFavorite(1,-1))
}
}

@ -34,23 +34,6 @@ class UnitTestUser {
)
}
@Test
fun testCreateUserEmptyUsername(){
assertFalse(services.CreateUser("", "email", "passwd")
)
}
@Test
fun testCreateUserEmptyEmail(){
assertFalse(services.CreateUser("usernameEmptyEmail", "", "passwd")
)
}
@Test
fun testCreateUserEmptyPassword(){
assertFalse(services.CreateUser("usernameEmptyPassword", "email", "")
)
}
@Test
fun testUserEditUsername_OK(){
services.CreateUser("username4", "email4", "passwd")

Loading…
Cancel
Save