Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2010 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.quicksearchbox.util;
     18 
     19 import android.test.suitebuilder.annotation.MediumTest;
     20 
     21 import java.util.concurrent.Executors;
     22 
     23 import junit.framework.TestCase;
     24 
     25 /**
     26  * Tests for {@link SingleThreadNamedTaskExecutor}.
     27  */
     28 @MediumTest
     29 public class SingleThreadNamedTaskExecutorTest extends TestCase {
     30 
     31     private SingleThreadNamedTaskExecutor mExecutor;
     32 
     33     @Override
     34     protected void setUp() throws Exception {
     35         super.setUp();
     36 
     37         mExecutor = new SingleThreadNamedTaskExecutor(Executors.defaultThreadFactory());
     38     }
     39 
     40     public void testExecute() throws Exception {
     41         MockTask a1 = addTask("a", 1);
     42         MockTask a2 = addTask("a", 2);
     43 
     44         // This just checks that the tasks run, and run in the right order
     45         a1.waitForCompletion();
     46         a2.waitForCompletion();
     47     }
     48 
     49     private MockTask addTask(String name, int id) {
     50         MockTask task = new MockTask(name, id);
     51         mExecutor.execute(task);
     52         return task;
     53     }
     54 
     55 }
     56