| 1 |
/* |
| 2 |
* Copyright (C) 2015 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
package android.databinding.testapp; |
| 17 |
|
| 18 |
import android.databinding.PropertyChangeRegistry; |
| 19 |
import android.databinding.testapp.databinding.BasicBindingBinding; |
| 20 |
|
| 21 |
import android.databinding.Observable; |
| 22 |
import android.databinding.Observable.OnPropertyChangedCallback; |
| 23 |
|
| 24 |
public class PropertyChangeRegistryTest extends BaseDataBinderTest<BasicBindingBinding> { |
| 25 |
|
| 26 |
private int notificationCount = 0; |
| 27 |
|
| 28 |
public PropertyChangeRegistryTest() { |
| 29 |
super(BasicBindingBinding.class); |
| 30 |
} |
| 31 |
|
| 32 |
public void testNotifyChanged() { |
| 33 |
PropertyChangeRegistry propertyChangeRegistry = new PropertyChangeRegistry(); |
| 34 |
|
| 35 |
final Observable observableObj = new Observable() { |
| 36 |
@Override |
| 37 |
public void addOnPropertyChangedCallback( |
| 38 |
OnPropertyChangedCallback OnPropertyChangedCallback) { |
| 39 |
} |
| 40 |
|
| 41 |
@Override |
| 42 |
public void removeOnPropertyChangedCallback( |
| 43 |
OnPropertyChangedCallback OnPropertyChangedCallback) { |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
final int expectedId = 100; |
| 48 |
OnPropertyChangedCallback listener = new OnPropertyChangedCallback() { |
| 49 |
@Override |
| 50 |
public void onPropertyChanged(Observable observable, int id) { |
| 51 |
notificationCount++; |
| 52 |
assertEquals(expectedId, id); |
| 53 |
assertEquals(observableObj, observable); |
| 54 |
} |
| 55 |
}; |
| 56 |
propertyChangeRegistry.add(listener); |
| 57 |
|
| 58 |
assertEquals(0, notificationCount); |
| 59 |
propertyChangeRegistry.notifyChange(observableObj, expectedId); |
| 60 |
assertEquals(1, notificationCount); |
| 61 |
} |
| 62 |
} |