-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
253 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
app/src/androidTest/java/es/unex/giis/asee/gepeto/view/TestCU13.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package es.unex.giis.asee.gepeto.view | ||
|
||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.* | ||
import androidx.test.espresso.assertion.ViewAssertions.* | ||
import androidx.test.espresso.matcher.ViewMatchers.* | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import es.unex.giis.asee.gepeto.R | ||
import org.hamcrest.Description | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.Matchers.allOf | ||
import org.hamcrest.Matchers.`is` | ||
import org.hamcrest.TypeSafeMatcher | ||
import org.hamcrest.core.IsInstanceOf | ||
import org.junit.After | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@LargeTest | ||
@RunWith(AndroidJUnit4::class) | ||
class TestCU13 { | ||
|
||
@Rule | ||
@JvmField | ||
var mActivityScenarioRule = ActivityScenarioRule(LoginActivity::class.java) | ||
|
||
@Test | ||
fun registerActivityTest() { | ||
val materialButton = onView( | ||
allOf( | ||
withId(R.id.bt_register), withText("Registrarse"), | ||
childAtPosition( | ||
childAtPosition( | ||
withClassName(`is`("android.widget.LinearLayout")), | ||
4 | ||
), | ||
1 | ||
) | ||
) | ||
) | ||
materialButton.perform(scrollTo(), click()) | ||
|
||
val appCompatEditText = onView( | ||
allOf( | ||
withId(R.id.et_username), | ||
childAtPosition( | ||
childAtPosition( | ||
withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")), | ||
3 | ||
), | ||
1 | ||
) | ||
) | ||
) | ||
appCompatEditText.perform(scrollTo(), replaceText("Espresso"), closeSoftKeyboard()) | ||
|
||
val appCompatEditText2 = onView( | ||
allOf( | ||
withId(R.id.et_password), | ||
childAtPosition( | ||
childAtPosition( | ||
withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")), | ||
3 | ||
), | ||
3 | ||
) | ||
) | ||
) | ||
appCompatEditText2.perform(scrollTo(), replaceText("Conazucar"), closeSoftKeyboard()) | ||
|
||
val appCompatEditText3 = onView( | ||
allOf( | ||
withId(R.id.et_repassword), | ||
childAtPosition( | ||
childAtPosition( | ||
withClassName(`is`("androidx.constraintlayout.widget.ConstraintLayout")), | ||
3 | ||
), | ||
5 | ||
) | ||
) | ||
) | ||
appCompatEditText3.perform(scrollTo(), replaceText("Conazucar"), closeSoftKeyboard()) | ||
|
||
val materialButton2 = onView( | ||
allOf( | ||
withId(R.id.bt_register), withText("Registrarse"), | ||
childAtPosition( | ||
childAtPosition( | ||
withClassName(`is`("android.widget.LinearLayout")), | ||
6 | ||
), | ||
0 | ||
) | ||
) | ||
) | ||
materialButton2.perform(scrollTo(), click()) | ||
|
||
val editText = onView( | ||
allOf( | ||
withId(R.id.et_username), withText("Espresso"), | ||
withParent(withParent(IsInstanceOf.instanceOf(android.view.ViewGroup::class.java))), | ||
isDisplayed() | ||
) | ||
) | ||
editText.check(matches(withText("Espresso"))) | ||
|
||
val editText2 = onView( | ||
allOf( | ||
withId(R.id.et_password), withText("Conazucar"), | ||
withParent(withParent(IsInstanceOf.instanceOf(android.view.ViewGroup::class.java))), | ||
isDisplayed() | ||
) | ||
) | ||
editText2.check(matches(withText("Conazucar"))) | ||
} | ||
|
||
private fun childAtPosition( | ||
parentMatcher: Matcher<View>, position: Int | ||
): Matcher<View> { | ||
|
||
return object : TypeSafeMatcher<View>() { | ||
override fun describeTo(description: Description) { | ||
description.appendText("Child at position $position in parent ") | ||
parentMatcher.describeTo(description) | ||
} | ||
|
||
public override fun matchesSafely(view: View): Boolean { | ||
val parent = view.parent | ||
return parent is ViewGroup && parentMatcher.matches(parent) | ||
&& view == parent.getChildAt(position) | ||
} | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
app/src/test/java/es/unex/giis/asee/gepeto/utils/CredentialCheckTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package es.unex.giis.asee.gepeto.utils | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockito.MockitoAnnotations | ||
|
||
class CredentialCheckTest { | ||
|
||
@Before | ||
fun setup() { | ||
} | ||
|
||
@Test | ||
fun login() { | ||
|
||
//Username vacío | ||
assertEquals("Invalid username", CredentialCheck.login("", "password123").msg) | ||
assertTrue(CredentialCheck.login("", "password123").fail) | ||
//Username corto | ||
assertEquals("Invalid username", CredentialCheck.login("abc", "password123").msg) | ||
assertTrue(CredentialCheck.login("abc", "password123").fail) | ||
//Password vacío | ||
assertEquals("Invalid password", CredentialCheck.login("username", "").msg) | ||
assertTrue(CredentialCheck.login("username", "").fail) | ||
//Password corto | ||
assertEquals("Invalid password", CredentialCheck.login("username", "abc").msg) | ||
assertTrue(CredentialCheck.login("username", "abc").fail) | ||
//Credenciales válidas | ||
assertEquals("Your credentials are OK", CredentialCheck.login("username", "password123").msg) | ||
assertFalse(CredentialCheck.login("username", "password123").fail) | ||
} | ||
|
||
|
||
@Test | ||
fun testPasswordOk() { | ||
// Password vacío | ||
assertEquals("Invalid password", CredentialCheck.passwordOk("", "password123").msg) | ||
assertTrue(CredentialCheck.passwordOk("", "password123").fail) | ||
|
||
// Password corto | ||
assertEquals("Invalid password", CredentialCheck.passwordOk("abc", "abc").msg) | ||
assertTrue(CredentialCheck.passwordOk("pass", "password123").fail) | ||
|
||
// Contraseñas no coinciden | ||
assertEquals("Passwords do not match", CredentialCheck.passwordOk("password123", "password456").msg) | ||
assertTrue(CredentialCheck.passwordOk("password123", "password456").fail) | ||
|
||
// Contraseñas válidas | ||
assertEquals("Your credentials are OK", CredentialCheck.passwordOk("password123", "password123").msg) | ||
assertFalse(CredentialCheck.passwordOk("password123", "password123").fail) | ||
} | ||
|
||
@Test | ||
fun testNewPasswordOk() { | ||
// Password vacío | ||
assertEquals("Invalid password", CredentialCheck.newPasswordOk("").msg) | ||
assertTrue(CredentialCheck.newPasswordOk("").fail) | ||
|
||
// Password corto | ||
assertEquals("Invalid password", CredentialCheck.newPasswordOk("abc").msg) | ||
assertTrue(CredentialCheck.newPasswordOk("abc").fail) | ||
|
||
// Contraseña válida | ||
assertEquals("Your credentials are OK", CredentialCheck.newPasswordOk("password123").msg) | ||
assertFalse(CredentialCheck.newPasswordOk("password123").fail) | ||
} | ||
|
||
@Test | ||
fun testJoin() { | ||
// Username vacío | ||
assertEquals("Invalid username", CredentialCheck.join("", "password123", "password123").msg) | ||
assertTrue(CredentialCheck.join("", "password123", "password123").fail) | ||
|
||
// Username corto | ||
assertEquals("Invalid username", CredentialCheck.join("abc", "password123", "password123").msg) | ||
assertTrue(CredentialCheck.join("abc", "password123", "password123").fail) | ||
|
||
// Password vacío | ||
assertEquals("Invalid password", CredentialCheck.join("username", "", "password123").msg) | ||
assertTrue(CredentialCheck.join("username", "", "password123").fail) | ||
|
||
// Password corto | ||
assertEquals("Invalid password", CredentialCheck.join("username", "abc", "password123").msg) | ||
assertTrue(CredentialCheck.join("username", "pass", "password123").fail) | ||
|
||
// Contraseñas no coinciden | ||
assertEquals("Passwords do not match", CredentialCheck.join("username", "password123", "password456").msg) | ||
assertTrue(CredentialCheck.join("username", "password123", "password456").fail) | ||
|
||
// Credenciales válidas | ||
assertEquals("Your credentials are OK", CredentialCheck.join("username", "password123", "password123").msg) | ||
assertFalse(CredentialCheck.join("username", "password123", "password123").fail) | ||
} | ||
} |