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 17 package com.android.documentsui.model; 18 19 import android.test.AndroidTestCase; 20 import android.test.suitebuilder.annotation.SmallTest; 21 22 @SmallTest 23 public class DocumentInfoTest extends AndroidTestCase { 24 25 private static final DocumentInfo TEST_DOC 26 = createDocInfo("authority.a", "doc.1", "text/plain"); 27 28 public void testEquals() throws Exception { 29 assertEquals(TEST_DOC, TEST_DOC); 30 assertEquals(TEST_DOC, createDocInfo("authority.a", "doc.1", "text/plain")); 31 } 32 33 public void testEquals_HandlesNulls() throws Exception { 34 assertFalse(TEST_DOC.equals(null)); 35 } 36 37 public void testEquals_HandlesNullFields() throws Exception { 38 assertFalse(TEST_DOC.equals(new DocumentInfo())); 39 assertFalse(new DocumentInfo().equals(TEST_DOC)); 40 } 41 42 public void testNotEquals_differentAuthority() throws Exception { 43 assertFalse(TEST_DOC.equals(createDocInfo("authority.b", "doc.1", "text/plain"))); 44 } 45 46 public void testNotEquals_differentDocId() throws Exception { 47 assertFalse(TEST_DOC.equals(createDocInfo("authority.a", "doc.2", "text/plain"))); 48 } 49 50 public void testNotEquals_differentMimetype() throws Exception { 51 assertFalse(TEST_DOC.equals(createDocInfo("authority.a", "doc.1", "image/png"))); 52 } 53 54 private static DocumentInfo createDocInfo(String authority, String docId, String mimeType) { 55 DocumentInfo doc = new DocumentInfo(); 56 doc.authority = authority; 57 doc.documentId = docId; 58 doc.mimeType = mimeType; 59 doc.deriveFields(); 60 return doc; 61 } 62 } 63