This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
childrenRecursiveSequence: fix NoSuchElementException being thrown wh…
…en hasNext() returned true (#388)
- Loading branch information
1 parent
61f3055
commit d2e3ff2
Showing
2 changed files
with
83 additions
and
22 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
anko/library/robolectricTests/src/test/java/ChildrenSequenceTest.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,70 @@ | ||
package test | ||
|
||
import android.app.Activity | ||
import android.os.Bundle | ||
import android.widget.LinearLayout | ||
import android.widget.RelativeLayout | ||
import android.widget.TextView | ||
import org.jetbrains.anko.* | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.Robolectric | ||
import org.robolectric.RobolectricGradleTestRunner | ||
import org.robolectric.annotation.Config | ||
|
||
open class ChildrenSequenceTestActivity: Activity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
verticalLayout { | ||
id = 1 | ||
|
||
relativeLayout { | ||
id = 2 | ||
textView { | ||
id = 3 | ||
} | ||
textView { | ||
id = 4 | ||
} | ||
relativeLayout { | ||
id = 5 | ||
textView { | ||
id = 6 | ||
} | ||
} | ||
} | ||
textView { | ||
id = 7 | ||
} | ||
} | ||
} | ||
} | ||
|
||
@RunWith(RobolectricGradleTestRunner::class) | ||
@Config(constants = BuildConfig::class) class ChildrenSequenceTest { | ||
@Test fun testChildrenSequence() { | ||
val activity = Robolectric.buildActivity(ChildrenSequenceTestActivity::class.java).create().get() | ||
|
||
val verticalLayout = activity.findViewById(1) as LinearLayout | ||
val relativeLayout = activity.findViewById(2) as RelativeLayout | ||
val textView = activity.findViewById(3) as TextView | ||
|
||
assertEquals(listOf(2, 7), verticalLayout.childrenSequence().map { it.id }.toList()) | ||
assertEquals(listOf(3, 4, 5), relativeLayout.childrenSequence().map { it.id }.toList()) | ||
assert(textView.childrenSequence().toList().isEmpty()) | ||
} | ||
|
||
@Test fun testChildrenRecursiveSequence() { | ||
val activity = Robolectric.buildActivity(ChildrenSequenceTestActivity::class.java).create().get() | ||
|
||
val verticalLayout = activity.findViewById(1) as LinearLayout | ||
val relativeLayout = activity.findViewById(2) as RelativeLayout | ||
val textView = activity.findViewById(3) as TextView | ||
|
||
assertEquals(listOf(2, 7, 3, 4, 5, 6), verticalLayout.childrenRecursiveSequence().map { it.id }.toList()) | ||
assertEquals(listOf(3, 4, 5, 6), relativeLayout.childrenRecursiveSequence().map { it.id }.toList()) | ||
assert(textView.childrenRecursiveSequence().toList().isEmpty()) | ||
} | ||
} |
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