Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 662d87aa authored by George Mount's avatar George Mount
Browse files

Moved classes from library to baseLibrary

Added tests for some classes.
parent 607fb140
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -51,10 +51,15 @@ android {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.databinding:library:0.3-SNAPSHOT'
    compile "com.android.support:support-v4:+"
    provided 'com.android.databinding:annotationprocessor:0.3-SNAPSHOT'
}
+237 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.databinding.testapp;

import com.android.databinding.library.ListChangeRegistry;
import com.android.databinding.testapp.generated.BasicBindingBinder;

import android.binding.OnListChangedListener;

public class ListChangeRegistryTest extends BaseDataBinderTest<BasicBindingBinder> {

    private ListChangeRegistry mListChangeRegistry;

    private int mCallCount;

    public ListChangeRegistryTest() {
        super(BasicBindingBinder.class, R.layout.basic_binding);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        mListChangeRegistry = new ListChangeRegistry();
        mCallCount = 0;
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
        mListChangeRegistry = null;
    }

    public void testNotifyChangedAll() {
        OnListChangedListener listChangedListener = new OnListChangedListener() {
            @Override
            public void onChanged() {
                mCallCount++;
            }

            @Override
            public void onItemRangeChanged(int start, int count) {
                fail("onItemRangeChanged should not be called");
            }

            @Override
            public void onItemRangeInserted(int start, int count) {
                fail("onItemRangeInserted should not be called");
            }

            @Override
            public void onItemRangeMoved(int from, int to, int count) {
                fail("onItemRangeMoved should not be called");
            }

            @Override
            public void onItemRangeRemoved(int start, int count) {
                fail("onItemRangeRemoved should not be called");
            }
        };

        mListChangeRegistry.add(listChangedListener);
        assertEquals(0, mCallCount);
        mListChangeRegistry.notifyChanged(null);
        assertEquals(1, mCallCount);
    }

    public void testNotifyChanged() {
        final int expectedStart = 10;
        final int expectedCount = 3;

        OnListChangedListener listChangedListener = new OnListChangedListener() {
            @Override
            public void onChanged() {
                fail("onChanged should not be called");
            }

            @Override
            public void onItemRangeChanged(int start, int count) {
                assertEquals(expectedStart, start);
                assertEquals(expectedCount, count);
                mCallCount++;
            }

            @Override
            public void onItemRangeInserted(int start, int count) {
                fail("onItemRangeInserted should not be called");
            }

            @Override
            public void onItemRangeMoved(int from, int to, int count) {
                fail("onItemRangeMoved should not be called");
            }

            @Override
            public void onItemRangeRemoved(int start, int count) {
                fail("onItemRangeRemoved should not be called");
            }
        };

        mListChangeRegistry.add(listChangedListener);
        assertEquals(0, mCallCount);
        mListChangeRegistry.notifyChanged(null, expectedStart, expectedCount);
        assertEquals(1, mCallCount);
    }

    public void testNotifyInserted() {
        final int expectedStart = 10;
        final int expectedCount = 3;

        OnListChangedListener listChangedListener = new OnListChangedListener() {
            @Override
            public void onChanged() {
                fail("onChanged should not be called");
            }

            @Override
            public void onItemRangeChanged(int start, int count) {
                fail("onItemRangeChanged should not be called");
            }

            @Override
            public void onItemRangeInserted(int start, int count) {
                assertEquals(expectedStart, start);
                assertEquals(expectedCount, count);
                mCallCount++;
            }

            @Override
            public void onItemRangeMoved(int from, int to, int count) {
                fail("onItemRangeMoved should not be called");
            }

            @Override
            public void onItemRangeRemoved(int start, int count) {
                fail("onItemRangeRemoved should not be called");
            }
        };

        mListChangeRegistry.add(listChangedListener);
        assertEquals(0, mCallCount);
        mListChangeRegistry.notifyInserted(null, expectedStart, expectedCount);
        assertEquals(1, mCallCount);
    }

    public void testNotifyMoved() {
        final int expectedFrom = 10;
        final int expectedTo = 100;
        final int expectedCount = 3;

        OnListChangedListener listChangedListener = new OnListChangedListener() {
            @Override
            public void onChanged() {
                fail("onChanged should not be called");
            }

            @Override
            public void onItemRangeChanged(int start, int count) {
                fail("onItemRangeChanged should not be called");
            }

            @Override
            public void onItemRangeInserted(int start, int count) {
                fail("onItemRangeInserted should not be called");
            }

            @Override
            public void onItemRangeMoved(int from, int to, int count) {
                assertEquals(expectedFrom, from);
                assertEquals(expectedTo, to);
                assertEquals(expectedCount, count);
                mCallCount++;
            }

            @Override
            public void onItemRangeRemoved(int start, int count) {
                fail("onItemRangeRemoved should not be called");
            }
        };

        mListChangeRegistry.add(listChangedListener);
        assertEquals(0, mCallCount);
        mListChangeRegistry.notifyMoved(null, expectedFrom, expectedTo, expectedCount);
        assertEquals(1, mCallCount);
    }

    public void testNotifyRemoved() {
        final int expectedStart = 10;
        final int expectedCount = 3;

        OnListChangedListener listChangedListener = new OnListChangedListener() {
            @Override
            public void onChanged() {
                fail("onChanged should not be called");
            }

            @Override
            public void onItemRangeChanged(int start, int count) {
                fail("onItemRangeChanged should not be called");
            }

            @Override
            public void onItemRangeInserted(int start, int count) {
                fail("onItemRangeInserted should not be called");
            }

            @Override
            public void onItemRangeMoved(int from, int to, int count) {
                fail("onItemRangeMoved should not be called");
            }

            @Override
            public void onItemRangeRemoved(int start, int count) {
                assertEquals(expectedStart, start);
                assertEquals(expectedCount, count);
                mCallCount++;
            }
        };

        mListChangeRegistry.add(listChangedListener);
        assertEquals(0, mCallCount);
        mListChangeRegistry.notifyRemoved(null, expectedStart, expectedCount);
        assertEquals(1, mCallCount);
    }
}
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.databinding.testapp;

import com.android.databinding.library.MapChangeRegistry;
import com.android.databinding.library.ObservableArrayMap;
import com.android.databinding.testapp.generated.BasicBindingBinder;

import android.binding.ObservableMap;
import android.binding.OnMapChangedListener;

public class MapChangeRegistryTest extends BaseDataBinderTest<BasicBindingBinder> {

    private int notificationCount = 0;

    public MapChangeRegistryTest() {
        super(BasicBindingBinder.class, R.layout.basic_binding);
    }

    public void testNotifyAllChanged() {
        MapChangeRegistry mapChangeRegistry = new MapChangeRegistry();

        final ObservableMap<String, Integer> observableObj = new ObservableArrayMap<>();

        final String expectedKey = "key";
        OnMapChangedListener listener = new OnMapChangedListener<ObservableMap<String, Integer>, String>() {
            @Override
            public void onMapChanged(ObservableMap sender, String key) {
                notificationCount++;
                assertEquals(observableObj, sender);
                assertEquals(key, expectedKey);
            }
        };
        mapChangeRegistry.add(listener);

        assertEquals(0, notificationCount);
        mapChangeRegistry.notifyChange(observableObj, expectedKey);
        assertEquals(1, notificationCount);
    }
}
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.databinding.testapp;

import com.android.databinding.library.PropertyChangeRegistry;
import com.android.databinding.testapp.generated.BasicBindingBinder;

import android.binding.Observable;
import android.binding.OnPropertyChangedListener;

public class PropertyChangeRegistryTest extends BaseDataBinderTest<BasicBindingBinder> {

    private int notificationCount = 0;

    public PropertyChangeRegistryTest() {
        super(BasicBindingBinder.class, R.layout.basic_binding);
    }

    public void testNotifyChanged() {
        PropertyChangeRegistry propertyChangeRegistry = new PropertyChangeRegistry();

        final Observable observableObj = new Observable() {
            @Override
            public void addOnPropertyChangedListener(
                    OnPropertyChangedListener onPropertyChangedListener) {
            }

            @Override
            public void removeOnPropertyChangedListener(
                    OnPropertyChangedListener onPropertyChangedListener) {
            }
        };

        final int expectedId = 100;
        OnPropertyChangedListener listener = new OnPropertyChangedListener() {
            @Override
            public void onPropertyChanged(Observable observable, int id) {
                notificationCount++;
                assertEquals(expectedId, id);
                assertEquals(observableObj, observable);
            }
        };
        propertyChangeRegistry.add(listener);

        assertEquals(0, notificationCount);
        propertyChangeRegistry.notifyChange(observableObj, expectedId);
        assertEquals(1, notificationCount);
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'application'

sourceCompatibility = 1.7
mainClassName = "org.antlr.v4.Tool"

buildscript {
    repositories {
@@ -34,6 +38,16 @@ sourceSets {
            srcDir 'src/main/java'
        }
    }
    test {
        java {
            srcDir 'src/test/java'
        }
    }
}

dependencies {
    compile 'com.tunnelvisionlabs:antlr4:4.4'
    testCompile 'junit:junit:4.11'
}

uploadArchives {
Loading