Home | History | Annotate | Download | only in concurrent
      1 /*
      2  * Copyright (C) 2013 The Guava Authors
      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.google.common.util.concurrent;
     18 
     19 import static com.google.common.util.concurrent.Service.State.FAILED;
     20 import static com.google.common.util.concurrent.Service.State.NEW;
     21 import static com.google.common.util.concurrent.Service.State.RUNNING;
     22 import static com.google.common.util.concurrent.Service.State.STARTING;
     23 import static com.google.common.util.concurrent.Service.State.STOPPING;
     24 import static com.google.common.util.concurrent.Service.State.TERMINATED;
     25 
     26 import junit.framework.TestCase;
     27 
     28 /**
     29  * Unit tests for {@link Service}
     30  */
     31 public class ServiceTest extends TestCase {
     32 
     33   /** Assert on the comparison ordering of the State enum since we guarantee it. */
     34   public void testStateOrdering() {
     35     // List every valid (direct) state transition.
     36     assertLessThan(NEW, STARTING);
     37     assertLessThan(NEW, TERMINATED);
     38 
     39     assertLessThan(STARTING, RUNNING);
     40     assertLessThan(STARTING, STOPPING);
     41     assertLessThan(STARTING, FAILED);
     42 
     43     assertLessThan(RUNNING, STOPPING);
     44     assertLessThan(RUNNING, FAILED);
     45 
     46     assertLessThan(STOPPING, FAILED);
     47     assertLessThan(STOPPING, TERMINATED);
     48   }
     49 
     50   private static <T extends Comparable<? super T>> void assertLessThan(T a, T b) {
     51     if (a.compareTo(b) >= 0) {
     52       fail(String.format("Expected %s to be less than %s", a, b));
     53     }
     54   }
     55 }
     56