Home | History | Annotate | Download | only in volley
      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.volley;
     18 
     19 import android.test.suitebuilder.annotation.SmallTest;
     20 
     21 import com.android.volley.Request.Priority;
     22 
     23 import junit.framework.TestCase;
     24 
     25 @SmallTest
     26 public class RequestTest extends TestCase {
     27     @Override
     28     protected void setUp() throws Exception {
     29         super.setUp();
     30     }
     31 
     32     public void testCompareTo() {
     33         int sequence = 0;
     34         TestRequest low = new TestRequest(Priority.LOW);
     35         low.setSequence(sequence++);
     36         TestRequest low2 = new TestRequest(Priority.LOW);
     37         low2.setSequence(sequence++);
     38         TestRequest high = new TestRequest(Priority.HIGH);
     39         high.setSequence(sequence++);
     40         TestRequest immediate = new TestRequest(Priority.IMMEDIATE);
     41         immediate.setSequence(sequence++);
     42 
     43         // "Low" should sort higher because it's really processing order.
     44         assertTrue(low.compareTo(high) > 0);
     45         assertTrue(high.compareTo(low) < 0);
     46         assertTrue(low.compareTo(low2) < 0);
     47         assertTrue(low.compareTo(immediate) > 0);
     48         assertTrue(immediate.compareTo(high) < 0);
     49     }
     50 
     51     private class TestRequest extends Request<Object> {
     52         private Priority mPriority = Priority.NORMAL;
     53         public TestRequest(Priority priority) {
     54             super("", null);
     55             mPriority = priority;
     56         }
     57 
     58         @Override
     59         public Priority getPriority() {
     60             return mPriority;
     61         }
     62 
     63         @Override
     64         protected void deliverResponse(Object response) {
     65         }
     66 
     67         @Override
     68         protected Response<Object> parseNetworkResponse(NetworkResponse response) {
     69             return null;
     70         }
     71     }
     72 }
     73