Android Open Source - SurgeTracker Application Test






From Project

Back to project page SurgeTracker.

License

The source code is released under:

MIT License

If you think the Android project SurgeTracker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bklimt.surgetracker;
//  ww  w  .  j  a  v  a  2  s  .c o m
import android.app.Application;
import android.test.ApplicationTestCase;

import com.bklimt.surgetracker.backbone.Collection;
import com.bklimt.surgetracker.backbone.Model;

import java.util.Comparator;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
    }

    public void testCollectionSort() {
        Comparator<Model> comparator = new Comparator<Model>() {
            @Override
            public int compare(Model lhs, Model rhs) {
                String lhsString = lhs.getString("key");
                String rhsString = rhs.getString("key");
                if (lhsString == null) {
                    return -1;
                }
                if (rhsString == null) {
                    return 1;
                }
                return lhsString.compareTo(rhsString);
            }
        };

        Collection<Model> collection = new Collection<Model>();
        collection.setComparator(comparator);

        Model model = new Model();
        model.set("key", "hello");
        model.set("order", 1);
        collection.add(model);

        model = new Model();
        model.set("key", "hello");
        model.set("order", 2);
        collection.add(model);

        model = new Model();
        collection.add(model);

        model = new Model();
        model.set("key", "world");
        collection.add(model);

        model = new Model();
        model.set("key", "apple");
        collection.add(model);

        assertEquals(5, collection.size());

        assertEquals(null, collection.get(0).get("key"));
        assertEquals("apple", collection.get(1).getString("key"));
        assertEquals("hello", collection.get(2).getString("key"));
        assertEquals(1, collection.get(2).getInt("order"));
        assertEquals("hello", collection.get(3).getString("key"));
        assertEquals(2, collection.get(3).getInt("order"));
        assertEquals("world", collection.get(4).getString("key"));
    }
}




Java Source Code List

com.bklimt.surgetracker.ApplicationTest.java
com.bklimt.surgetracker.SurgeTrackerApplication.java
com.bklimt.surgetracker.TimerThread.java
com.bklimt.surgetracker.backbone.CollectionListener.java
com.bklimt.surgetracker.backbone.Collection.java
com.bklimt.surgetracker.backbone.ModelListener.java
com.bklimt.surgetracker.backbone.Model.java
com.bklimt.surgetracker.backbone.Visitor.java
com.bklimt.surgetracker.model.AggregateCollection.java
com.bklimt.surgetracker.model.Aggregate.java
com.bklimt.surgetracker.model.RootViewModel.java
com.bklimt.surgetracker.model.SurgeCollection.java
com.bklimt.surgetracker.model.SurgeParseObject.java
com.bklimt.surgetracker.model.Surge.java
com.bklimt.surgetracker.view.AggregateListAdapter.java
com.bklimt.surgetracker.view.AggregateListFragment.java
com.bklimt.surgetracker.view.MainActivity.java
com.bklimt.surgetracker.view.SurgeDeletionDialogFragment.java
com.bklimt.surgetracker.view.SurgeDurationDialogFragment.java
com.bklimt.surgetracker.view.SurgeGraphFragment.java
com.bklimt.surgetracker.view.SurgeListAdapter.java
com.bklimt.surgetracker.view.SurgeListFragment.java
com.bklimt.surgetracker.view.SurgeStartDialogFragment.java