| 1 |
package android.databinding.testapp; |
| 2 |
|
| 3 |
import android.databinding.OnRebindCallback; |
| 4 |
import android.databinding.ViewDataBinding; |
| 5 |
import android.databinding.testapp.databinding.InvalidateAllLayoutBinding; |
| 6 |
import android.databinding.testapp.vo.NotBindableVo; |
| 7 |
|
| 8 |
import java.util.concurrent.Semaphore; |
| 9 |
import java.util.concurrent.TimeUnit; |
| 10 |
|
| 11 |
public class InvalidateAllTest extends BaseDataBinderTest<InvalidateAllLayoutBinding> { |
| 12 |
|
| 13 |
public InvalidateAllTest() { |
| 14 |
super(InvalidateAllLayoutBinding.class); |
| 15 |
} |
| 16 |
|
| 17 |
public void testRefreshViaInvalidateAll() throws InterruptedException { |
| 18 |
final Semaphore semaphore = new Semaphore(1); |
| 19 |
semaphore.acquire(); |
| 20 |
final NotBindableVo vo = new NotBindableVo("foo"); |
| 21 |
initBinder(new Runnable() { |
| 22 |
@Override |
| 23 |
public void run() { |
| 24 |
mBinder.setVo(vo); |
| 25 |
mBinder.addOnRebindCallback(new OnRebindCallback() { |
| 26 |
@Override |
| 27 |
public void onBound(ViewDataBinding binding) { |
| 28 |
super.onBound(binding); |
| 29 |
semaphore.release(); |
| 30 |
} |
| 31 |
}); |
| 32 |
} |
| 33 |
}); |
| 34 |
assertTrue(semaphore.tryAcquire(2, TimeUnit.SECONDS)); |
| 35 |
|
| 36 |
assertEquals("foo", mBinder.textView.getText().toString()); |
| 37 |
vo.setStringValue("bar"); |
| 38 |
mBinder.invalidateAll(); |
| 39 |
|
| 40 |
assertTrue(semaphore.tryAcquire(2, TimeUnit.SECONDS)); |
| 41 |
assertEquals("bar", mBinder.textView.getText().toString()); |
| 42 |
|
| 43 |
} |
| 44 |
} |