Merge "Add a unit test to the sample project."
This commit is contained in:
committed by
Android (Google) Code Review
commit
0710ff5b59
@@ -66,4 +66,7 @@ dependencies {
|
||||
//provided 'com.android.databinding:compiler:0.3-SNAPSHOT'
|
||||
provided 'com.android.databinding:annotationprocessor:0.3-SNAPSHOT'
|
||||
provided fileTree(dir : 'build/databinder/src', include : ['*.java'])
|
||||
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'org.mockito:mockito-core:1.9.5'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.android.example.bindingdemo.vo;
|
||||
|
||||
import android.binding.OnPropertyChangedListener;
|
||||
|
||||
import com.android.example.bindingdemo.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
public class UnitTest {
|
||||
|
||||
private User testUser;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
testUser = new User("Ted", "Tester", R.drawable.george, User.ROBOT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settersWorkFineOnTheJvm() throws Exception {
|
||||
assertEquals("Ted", testUser.getName());
|
||||
testUser.setName("Tom");
|
||||
assertEquals("Tom", testUser.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listeners() throws Exception {
|
||||
OnPropertyChangedListener mockListener = mock(OnPropertyChangedListener.class);
|
||||
testUser.addOnPropertyChangedListener(mockListener);
|
||||
testUser.setName("Tom");
|
||||
verify(mockListener).onPropertyChanged(testUser, android.binding.BR.name);
|
||||
verifyNoMoreInteractions(mockListener);
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:1.0.0"
|
||||
classpath "com.android.tools.build:gradle:1.1.3"
|
||||
classpath 'com.android.databinding:dataBinder:0.3-SNAPSHOT'
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
||||
Reference in New Issue
Block a user