Back to project page android-memento.
The source code is released under:
Apache License
If you think the Android project android-memento listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * android-memento-lib https://github.com/twofortyfouram/android-memento * Copyright 2014 two forty four a.m. LLC *//from ww w . j av a 2s .co m * 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.twofortyfouram.memento.provider.sqlite; import junit.framework.TestCase; import android.content.ContentResolver; import android.net.Uri; import android.support.annotation.NonNull; import android.test.MoreAsserts; import android.test.suitebuilder.annotation.SmallTest; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; /** * Tests {@link com.twofortyfouram.memento.provider.sqlite.SqliteUriMatch}. */ public final class SqliteUriMatchTest extends TestCase { /** * @return A test content URI. */ @SmallTest @NonNull private static Uri getTestUri() { return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) .authority("com.twofortyfouram.memento.test.authority").build(); //$NON-NLS-1$ } /** * @return A test content URI. */ @SmallTest @NonNull private static Collection<Uri> getTestUris() { final Collection<Uri> uris = new ArrayList<Uri>(1); uris.add(getTestUri()); return uris; } @SmallTest public static void testGetMimeType() { final Uri testUri = getTestUri(); final SqliteUriMatch match = new SqliteUriMatch(testUri, getTestUris(), "test_table", "test_mime", true, new HashMap<String, String>()); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals("test_mime", match.getMimeType()); //$NON-NLS-1$ } @SmallTest public static void testGetTableName() { final Uri testUri = getTestUri(); final SqliteUriMatch match = new SqliteUriMatch(testUri, getTestUris(), "test_table", "test_mime", true, new HashMap<String, String>()); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals("test_table", match.getTableName()); //$NON-NLS-1$ } @SmallTest public static void testGetUri() { final Uri testUri = getTestUri(); final SqliteUriMatch match = new SqliteUriMatch(testUri, getTestUris(), "test_table", "test_mime", true, new HashMap<String, String>()); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(testUri, match.getBaseUri()); } @SmallTest public static void testIsIdUri_false() { final Uri testUri = getTestUri(); final SqliteUriMatch match = new SqliteUriMatch(testUri, getTestUris(), "test_table", "test_mime", false, new HashMap<String, String>()); //$NON-NLS-1$ //$NON-NLS-2$ assertFalse(match.isIdUri()); } @SmallTest public static void testIsIdUri_true() { final Uri testUri = getTestUri(); final SqliteUriMatch match = new SqliteUriMatch(testUri, getTestUris(), "test_table", "test_mime", true, new HashMap<String, String>()); //$NON-NLS-1$ //$NON-NLS-2$ assertTrue(match.isIdUri()); } @SmallTest public static void testGetProjectionMap() { final Map<String, String> projectionMap = new HashMap<String, String>(); projectionMap.put("column", "column"); final SqliteUriMatch match = new SqliteUriMatch(getTestUri(), getTestUris(), "test_table", "test_mime", true, projectionMap); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(projectionMap, match.getProjectionMap()); // Ensure object cannot be mutated projectionMap.clear(); assertFalse(match.getProjectionMap().isEmpty()); // Ensure return value cannot mutate object internals try { match.getProjectionMap().clear(); fail(); } catch (final UnsupportedOperationException e) { // Expected exception. } } @SmallTest public static void testGetUris() { final Collection<Uri> uris = getTestUris(); final SqliteUriMatch match = new SqliteUriMatch(getTestUri(), uris, "test_table", "test_mime", true, new HashMap<String, String>()); //$NON-NLS-1$ //$NON-NLS-2$ assertEquals(1, match.getNotifyUris().size()); assertTrue(match.getNotifyUris().contains(getTestUri())); // Ensure object cannot be mutated uris.clear(); assertFalse(match.getNotifyUris().isEmpty()); // Ensure return value cannot mutate object internals try { match.getNotifyUris().clear(); fail(); } catch (final UnsupportedOperationException e) { // Expected exception. } } }