1 /*
2  * Copyright (C) 2011 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.providers.contacts.util;
18 
19 import android.test.suitebuilder.annotation.SmallTest;
20 
21 import com.android.providers.contacts.FixedAndroidTestCase;
22 
23 /**
24  * Unit tests for {@link SelectionBuilder}.
25  */
26 @SmallTest
27 public class SelectionBuilderTest extends FixedAndroidTestCase {
testEmptyClauses()28     public void testEmptyClauses() {
29         assertEquals(null, new SelectionBuilder(null).build());
30         assertEquals(null, new SelectionBuilder("").build());
31         assertEquals(null, new SelectionBuilder("").addClause(null).build());
32         assertEquals(null, new SelectionBuilder(null).addClause("").build());
33         assertEquals(null, new SelectionBuilder(null).addClause("").addClause(null).build());
34     }
35 
testNonEmptyClauses()36     public void testNonEmptyClauses() {
37         assertEquals("(A)", new SelectionBuilder("A").build());
38         assertEquals("(A) AND (B=bar) AND (C='1')", new SelectionBuilder("A")
39                 .addClause("B=bar")
40                 .addClause("C='1'")
41                 .build());
42 
43         // Skips null and empty clauses.
44         assertEquals("(A) AND (B) AND (C)", new SelectionBuilder("A")
45                 .addClause("")
46                 .addClause("B")
47                 .addClause(null)
48                 .addClause("C")
49                 .addClause(null)
50                 .build());
51 
52         // Use base selection with constructor.
53         assertEquals("(A)", new SelectionBuilder(null).addClause("A").build());
54         assertEquals("(A)", new SelectionBuilder("").addClause("A").build());
55         assertEquals("(A) AND (B)", new SelectionBuilder("A").addClause("B").build());
56     }
57 }
58