Android Open Source - Multi-Mania-app Calendar Test






From Project

Back to project page Multi-Mania-app.

License

The source code is released under:

MIT License

If you think the Android project Multi-Mania-app 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 be.ana.nmct.multimania;
/*  ww w .  j av  a 2  s  .  co m*/
import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CalendarContract;
import android.test.ApplicationTestCase;

import java.text.ParseException;

import be.ana.nmct.multimania.model.Talk;
import be.ana.nmct.multimania.utils.GoogleCalUtil;
import be.ana.nmct.multimania.utils.SettingsUtil;
import be.ana.nmct.multimania.utils.Utility;

/**
 * Created by Axel on 12/11/2014.
 */

/**
 * This class tests the Calendar functionality
 */
public class CalendarTest extends ApplicationTestCase<Application> {

    private final String TAG = this.getClass().getSimpleName();

    private static final String CALENDAR_NAME = "Multi-Mania 2015";
    private static final String ACCOUNT_NAME = "ana@gmail.com";

    private static Talk sTestTalk;
    private static GoogleCalUtil sCalUtil;

    private ContentResolver mContentResolver;

    static {
        try {
            sTestTalk = new Talk(1, "Test talk", Utility.convertStringToDate("2014-05-19 10:45:00"), Utility.convertStringToDate("2014-05-19 11:30:00"), "TestDescription", 1, false);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    public CalendarTest() {
        super(Application.class);
    }

    @Override
    public void setContext(Context context) {
        super.setContext(context);
        mContentResolver = context.getContentResolver();
    }

    /**
     * This method gets the account set in SharedPreferences by the user
     * @throws Exception An unknown exception
     */
    @Override
    public void setUp() throws Exception {
        super.setUp();

        //Set shared preferences
        SettingsUtil util = new SettingsUtil(this.getContext(), GoogleCalUtil.PREFERENCE_NAME);
        util.setPreference(GoogleCalUtil.PREFERENCE_ACCOUNTNAME, ACCOUNT_NAME);
    }

    /**
     * Gets the Calendar via CalendarContract
     * @return A Cursor containing the Calendar
     */
    private Cursor getCalendarCursor() {
        ContentResolver cr = mContentResolver;
        Uri uri = CalendarContract.Calendars.CONTENT_URI;
        String selection = "((" + CalendarContract.Calendars.ACCOUNT_NAME + " = ?) AND ("
                + CalendarContract.Calendars.ACCOUNT_TYPE + " = ?) AND ("
                + CalendarContract.Calendars.OWNER_ACCOUNT + " = ?))";
        String[] selectionArgs = new String[]{ACCOUNT_NAME, CalendarContract.ACCOUNT_TYPE_LOCAL, ACCOUNT_NAME};
        return cr.query(uri, null, selection, selectionArgs, null);
    }

    /**
     * Gets an event by id
     * @param id the id of the event to get
     * @return A Cursor containing the id
     */
    public Cursor getEventByID(long id) {
        ContentResolver cr = mContentResolver;

        final String[] PROJECTION = new String[]{
                CalendarContract.Events._ID,
                CalendarContract.Events.TITLE,
                CalendarContract.Events.DESCRIPTION,
                CalendarContract.Events.EVENT_LOCATION,
                CalendarContract.Events.DTSTART,
                CalendarContract.Events.DTEND,
        };
        final String selection = "(" + CalendarContract.Events.OWNER_ACCOUNT + " = ? AND " + CalendarContract.Events._ID + " = ?)";
        final String[] selectionArgs = new String[]{ACCOUNT_NAME, id + ""};

        return cr.query(sCalUtil.buildCalUri(), PROJECTION, selection, selectionArgs, null);
    }

    /**
     * This method tests if a Calendar was successfully created
     */
    public void testCalendarCreated() {

        //Create the calendar
        sCalUtil = new GoogleCalUtil(this.getContext(), CALENDAR_NAME);
        sCalUtil.createCalendar();

        Cursor c = getCalendarCursor();

        assertNotNull(c);
        int calCount = c.getCount();
        assertTrue(calCount == 1);

        c.moveToFirst();
        int nameIndex = c.getColumnIndexOrThrow(CalendarContract.Calendars.ACCOUNT_NAME);
        String accountName = c.getString(nameIndex);

        assertTrue(accountName.equals(ACCOUNT_NAME));
    }

  /*  public void testAddEventToCalendar() {

        //Add talk to calendar
        sCalUtil = new GoogleCalUtil(this.getContext(), CALENDAR_NAME);
        sTestTalk.calEventId = sCalUtil.addTalk(sTestTalk);

        //Check if event was added to the calendar
        Cursor c = getEventByID(sTestTalk.calEventId);
        final int TITLE_INDEX = 1;
        String title;

        c.moveToFirst();
        title = c.getString(TITLE_INDEX);

        assertTrue(title.equals(sTestTalk.title));
    }
*/

    /**
     * This method tests if a Calendar was successfully deleted
     */
    public void testCalendarDeleted() {
        //Delete the calendar
        sCalUtil = new GoogleCalUtil(this.getContext(), CALENDAR_NAME);
        sCalUtil.deleteCalendar();

        //Check if calendar still exists
        Cursor c = getCalendarCursor();
        int calCount = c.getCount();
        assertTrue(calCount == 0);
    }
}




Java Source Code List

be.ana.nmct.multimania.ApiTest.java
be.ana.nmct.multimania.ApplicationTest.java
be.ana.nmct.multimania.CalendarTest.java
be.ana.nmct.multimania.DbTest.java
be.ana.nmct.multimania.Import.java
be.ana.nmct.multimania.NotificationImport.java
be.ana.nmct.multimania.ProviderTest.java
be.ana.nmct.multimania.SyncTest.java
be.ana.nmct.multimania.data.ApiActions.java
be.ana.nmct.multimania.data.DbHelper.java
be.ana.nmct.multimania.data.GsonLoader.java
be.ana.nmct.multimania.data.MultimaniaContract.java
be.ana.nmct.multimania.data.MultimaniaProvider.java
be.ana.nmct.multimania.data.NewsItemLoader.java
be.ana.nmct.multimania.data.RoomLoader.java
be.ana.nmct.multimania.data.TagLoader.java
be.ana.nmct.multimania.data.TalkLoader.java
be.ana.nmct.multimania.model.IData.java
be.ana.nmct.multimania.model.NewsItem.java
be.ana.nmct.multimania.model.Room.java
be.ana.nmct.multimania.model.Speaker.java
be.ana.nmct.multimania.model.Tag.java
be.ana.nmct.multimania.model.TalkSpeaker.java
be.ana.nmct.multimania.model.TalkTag.java
be.ana.nmct.multimania.model.Talk.java
be.ana.nmct.multimania.model.User.java
be.ana.nmct.multimania.service.AuthenticatorService.java
be.ana.nmct.multimania.service.Authenticator.java
be.ana.nmct.multimania.service.BootListener.java
be.ana.nmct.multimania.service.NotificationReceiver.java
be.ana.nmct.multimania.service.NotificationSender.java
be.ana.nmct.multimania.service.SyncAdapter.java
be.ana.nmct.multimania.service.SyncService.java
be.ana.nmct.multimania.ui.AboutFragment.java
be.ana.nmct.multimania.ui.LoadActivity.java
be.ana.nmct.multimania.ui.MainActivity.java
be.ana.nmct.multimania.ui.MapFragment.java
be.ana.nmct.multimania.ui.MyScheduleFragment.java
be.ana.nmct.multimania.ui.MySchedulesFragment.java
be.ana.nmct.multimania.ui.NavigationDrawerFragment.java
be.ana.nmct.multimania.ui.NewsFragment.java
be.ana.nmct.multimania.ui.NewsItemActivity.java
be.ana.nmct.multimania.ui.NewsItemFragment.java
be.ana.nmct.multimania.ui.ScheduleFragment.java
be.ana.nmct.multimania.ui.SchedulesFragment.java
be.ana.nmct.multimania.ui.SettingsFragment.java
be.ana.nmct.multimania.ui.SuggestionFragment.java
be.ana.nmct.multimania.ui.TalkActivity.java
be.ana.nmct.multimania.ui.TalkFragment.java
be.ana.nmct.multimania.utils.GoogleCalUtil.java
be.ana.nmct.multimania.utils.SettingsHelper.java
be.ana.nmct.multimania.utils.SettingsUtil.java
be.ana.nmct.multimania.utils.SyncUtils.java
be.ana.nmct.multimania.utils.Utility.java
be.ana.nmct.multimania.vm.NavigationItem.java
be.ana.nmct.multimania.vm.ScheduleTalkVm.java
be.ana.nmct.multimania.widget.StaggeredGridView.java
com.bulletnoid.android.widget.StaggeredGridView.BulletStaggeredGridView.java
com.bulletnoid.android.widget.StaggeredGridView.HeaderFooterListAdapter.java
com.bulletnoid.android.widget.StaggeredGridView.ScrollerCompatIcs.java
com.bulletnoid.android.widget.StaggeredGridView.ScrollerCompat.java