1 package com.android.example.bindingdemo.vo;
2 
3 import android.databinding.OnPropertyChangedListener;
4 
5 import com.android.example.bindingdemo.R;
6 
7 import org.junit.Before;
8 import org.junit.Test;
9 
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.Mockito.verifyNoMoreInteractions;
14 
15 import com.android.example.bindingdemo.BR;
16 public class UnitTest {
17 
18     private User testUser;
19 
20     @Before
setUp()21     public void setUp() throws Exception {
22         testUser = new User("Ted", "Tester", R.drawable.george, User.ROBOTS);
23     }
24 
25     @Test
settersWorkFineOnTheJvm()26     public void settersWorkFineOnTheJvm() throws Exception {
27         assertEquals("Ted", testUser.getName());
28         testUser.setName("Tom");
29         assertEquals("Tom", testUser.getName());
30     }
31 
32     @Test
listeners()33     public void listeners() throws Exception {
34         OnPropertyChangedListener mockListener = mock(OnPropertyChangedListener.class);
35         testUser.addOnPropertyChangedListener(mockListener);
36         testUser.setName("Tom");
37         verify(mockListener).onPropertyChanged(testUser, BR.name);
38         verifyNoMoreInteractions(mockListener);
39     }
40 }
41