-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
ButterKnifeTest.java
38 lines (31 loc) · 1.11 KB
/
ButterKnifeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package butterknife;
import android.content.Context;
import android.view.View;
import androidx.test.InstrumentationRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static com.google.common.truth.Truth.assertThat;
public class ButterKnifeTest {
private final Context context = InstrumentationRegistry.getContext();
@Before @After // Clear out cache of binders before and after each test.
public void resetViewsCache() {
ButterKnife.BINDINGS.clear();
}
@Test public void zeroBindingsBindDoesNotThrowExceptionAndCaches() {
class Example {
}
Example example = new Example();
View view = new View(context);
assertThat(ButterKnife.BINDINGS).isEmpty();
assertThat(ButterKnife.bind(example, view)).isSameAs(Unbinder.EMPTY);
assertThat(ButterKnife.BINDINGS).containsEntry(Example.class, null);
}
@Test public void bindingKnownPackagesIsNoOp() {
View view = new View(context);
ButterKnife.bind(view);
assertThat(ButterKnife.BINDINGS).isEmpty();
ButterKnife.bind(new Object(), view);
assertThat(ButterKnife.BINDINGS).isEmpty();
}
}