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