-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port some resource binding tests to be functional.
- Loading branch information
1 parent
dc88730
commit cda0bad
Showing
16 changed files
with
278 additions
and
526 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
59 changes: 59 additions & 0 deletions
59
butterknife/src/androidTest/java/butterknife/functional/BindArrayTest.java
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,59 @@ | ||
package butterknife.functional; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import butterknife.BindArray; | ||
import butterknife.Unbinder; | ||
import butterknife.test.R; | ||
import org.junit.Test; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
public final class BindArrayTest { | ||
private final Context context = InstrumentationRegistry.getContext(); | ||
|
||
static class StringArrayTarget { | ||
@BindArray(R.array.string_one_two_three) String[] actual; | ||
} | ||
|
||
@Test public void asStringArray() { | ||
StringArrayTarget target = new StringArrayTarget(); | ||
String[] expected = context.getResources().getStringArray(R.array.string_one_two_three); | ||
|
||
Unbinder unbinder = new BindArrayTest$StringArrayTarget_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
|
||
static class IntArrayTarget { | ||
@BindArray(R.array.int_one_two_three) int[] actual; | ||
} | ||
|
||
@Test public void asIntArray() { | ||
IntArrayTarget target = new IntArrayTarget(); | ||
int[] expected = context.getResources().getIntArray(R.array.int_one_two_three); | ||
|
||
Unbinder unbinder = new BindArrayTest$IntArrayTarget_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
|
||
static class CharSequenceArrayTarget { | ||
@BindArray(R.array.int_one_two_three) CharSequence[] actual; | ||
} | ||
|
||
@Test public void asCharSequenceArray() { | ||
CharSequenceArrayTarget target = new CharSequenceArrayTarget(); | ||
CharSequence[] expected = context.getResources().getTextArray(R.array.int_one_two_three); | ||
|
||
Unbinder unbinder = new BindArrayTest$CharSequenceArrayTarget_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
butterknife/src/androidTest/java/butterknife/functional/BindBoolTest.java
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,29 @@ | ||
package butterknife.functional; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import butterknife.BindBool; | ||
import butterknife.Unbinder; | ||
import butterknife.test.R; | ||
import org.junit.Test; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
public final class BindBoolTest { | ||
private final Context context = InstrumentationRegistry.getContext(); | ||
|
||
static class Target { | ||
@BindBool(R.bool.just_true) boolean actual; | ||
} | ||
|
||
@Test public void asBoolean() { | ||
Target target = new Target(); | ||
boolean expected = context.getResources().getBoolean(R.bool.just_true); | ||
|
||
Unbinder unbinder = new BindBoolTest$Target_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
butterknife/src/androidTest/java/butterknife/functional/BindColorTest.java
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,29 @@ | ||
package butterknife.functional; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import butterknife.BindColor; | ||
import butterknife.Unbinder; | ||
import butterknife.test.R; | ||
import org.junit.Test; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
public final class BindColorTest { | ||
private final Context context = InstrumentationRegistry.getContext(); | ||
|
||
static class Target { | ||
@BindColor(R.color.red) int actual; | ||
} | ||
|
||
@Test public void asInt() { | ||
Target target = new Target(); | ||
int expected = context.getResources().getColor(R.color.red); | ||
|
||
Unbinder unbinder = new BindColorTest$Target_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
butterknife/src/androidTest/java/butterknife/functional/BindDimenTest.java
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,44 @@ | ||
package butterknife.functional; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import butterknife.BindDimen; | ||
import butterknife.Unbinder; | ||
import butterknife.test.R; | ||
import org.junit.Test; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
public final class BindDimenTest { | ||
private final Context context = InstrumentationRegistry.getContext(); | ||
|
||
static class IntTarget { | ||
@BindDimen(R.dimen.twelve_point_two_dp) int actual; | ||
} | ||
|
||
@Test public void asInt() { | ||
IntTarget target = new IntTarget(); | ||
int expected = context.getResources().getDimensionPixelSize(R.dimen.twelve_point_two_dp); | ||
|
||
Unbinder unbinder = new BindDimenTest$IntTarget_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
|
||
static class FloatTarget { | ||
@BindDimen(R.dimen.twelve_point_two_dp) float actual; | ||
} | ||
|
||
@Test public void asFloat() { | ||
FloatTarget target = new FloatTarget(); | ||
float expected = context.getResources().getDimension(R.dimen.twelve_point_two_dp); | ||
|
||
Unbinder unbinder = new BindDimenTest$FloatTarget_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
butterknife/src/androidTest/java/butterknife/functional/BindFloatTest.java
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,33 @@ | ||
package butterknife.functional; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.util.TypedValue; | ||
import butterknife.BindFloat; | ||
import butterknife.BindInt; | ||
import butterknife.Unbinder; | ||
import butterknife.test.R; | ||
import org.junit.Test; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
public final class BindFloatTest { | ||
private final Context context = InstrumentationRegistry.getContext(); | ||
|
||
static class Target { | ||
@BindFloat(R.dimen.twelve_point_two) float actual; | ||
} | ||
|
||
@Test public void asFloat() { | ||
Target target = new Target(); | ||
TypedValue value = new TypedValue(); | ||
context.getResources().getValue(R.dimen.twelve_point_two, value, true); | ||
float expected = value.getFloat(); | ||
|
||
Unbinder unbinder = new BindFloatTest$Target_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
butterknife/src/androidTest/java/butterknife/functional/BindIntTest.java
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,29 @@ | ||
package butterknife.functional; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import butterknife.BindInt; | ||
import butterknife.Unbinder; | ||
import butterknife.test.R; | ||
import org.junit.Test; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
public final class BindIntTest { | ||
private final Context context = InstrumentationRegistry.getContext(); | ||
|
||
static class Target { | ||
@BindInt(R.integer.twelve) int actual; | ||
} | ||
|
||
@Test public void asInt() { | ||
Target target = new Target(); | ||
int expected = context.getResources().getInteger(R.integer.twelve); | ||
|
||
Unbinder unbinder = new BindIntTest$Target_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
butterknife/src/androidTest/java/butterknife/functional/BindStringTest.java
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,29 @@ | ||
package butterknife.functional; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import butterknife.BindString; | ||
import butterknife.Unbinder; | ||
import butterknife.test.R; | ||
import org.junit.Test; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
public final class BindStringTest { | ||
private final Context context = InstrumentationRegistry.getContext(); | ||
|
||
static class Target { | ||
@BindString(R.string.hey) String actual; | ||
} | ||
|
||
@Test public void simpleInt() { | ||
Target target = new Target(); | ||
String expected = context.getString(R.string.hey); | ||
|
||
Unbinder unbinder = new BindStringTest$Target_ViewBinding(target, context); | ||
assertThat(target.actual).isEqualTo(expected); | ||
|
||
unbinder.unbind(); | ||
assertThat(target.actual).isEqualTo(expected); | ||
} | ||
} |
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,18 @@ | ||
<resources> | ||
<bool name="just_true">true</bool> | ||
<color name="red">#ffff0000</color> | ||
<integer name="twelve">12</integer> | ||
<dimen name="twelve_point_two_dp">12.2dp</dimen> | ||
<item name="twelve_point_two" format="float" type="dimen">12.2</item> | ||
<string name="hey">Hey</string> | ||
<string-array name="string_one_two_three"> | ||
<item>One</item> | ||
<item>Two</item> | ||
<item>Three</item> | ||
</string-array> | ||
<integer-array name="int_one_two_three"> | ||
<item>1</item> | ||
<item>2</item> | ||
<item>3</item> | ||
</integer-array> | ||
</resources> |
Oops, something went wrong.