-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override
onMeasure
for use default width/height for wrap_content
- Loading branch information
1 parent
ce866fe
commit 52f0410
Showing
2 changed files
with
87 additions
and
0 deletions.
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
60 changes: 60 additions & 0 deletions
60
camerabutton/src/test/java/com/hluhovskyi/camerabutton/OnMeasureTest.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,60 @@ | ||
package com.hluhovskyi.camerabutton | ||
|
||
import android.support.annotation.DimenRes | ||
import android.view.View | ||
import junit.framework.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.RuntimeEnvironment | ||
import org.robolectric.annotation.Config | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
@Config(constants = BuildConfig::class) | ||
class OnMeasureTest { | ||
|
||
private lateinit var button: CameraButton | ||
|
||
@Before | ||
fun setUp() { | ||
button = CameraButton(RuntimeEnvironment.application) | ||
} | ||
|
||
@Test | ||
fun atMost() { | ||
val widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.AT_MOST) | ||
val heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.AT_MOST) | ||
|
||
button.onMeasure(widthSpec, heightSpec) | ||
|
||
assertEquals(getDimen(R.dimen.cb_layout_width_default), button.measuredWidth) | ||
assertEquals(getDimen(R.dimen.cb_layout_height_default), button.measuredHeight) | ||
} | ||
|
||
@Test | ||
fun unspecified() { | ||
val widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) | ||
val heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) | ||
|
||
button.onMeasure(widthSpec, heightSpec) | ||
|
||
assertEquals(getDimen(R.dimen.cb_layout_width_default), button.measuredWidth) | ||
assertEquals(getDimen(R.dimen.cb_layout_height_default), button.measuredHeight) | ||
} | ||
|
||
@Test | ||
fun exactly() { | ||
val widthSpec = View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY) | ||
val heightSpec = View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY) | ||
|
||
button.onMeasure(widthSpec, heightSpec) | ||
|
||
assertEquals(100, button.measuredWidth) | ||
assertEquals(100, button.measuredHeight) | ||
} | ||
|
||
private fun getDimen(@DimenRes dimenRes: Int) = | ||
RuntimeEnvironment.application.resources | ||
.getDimensionPixelSize(R.dimen.cb_layout_width_default) | ||
} |