Import atomix/{storage,utils}
[controller.git] / third-party / atomix / utils / src / test / java / io / atomix / utils / GenericsTest.java
1 /*
2  * Copyright 2018-present Open Networking Foundation
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 package io.atomix.utils;
17
18 import org.junit.Test;
19
20 import static org.junit.Assert.assertEquals;
21
22 /**
23  * Generics test.
24  */
25 public class GenericsTest {
26   @Test
27   public void testGetInterfaceType() throws Exception {
28     assertEquals(String.class, Generics.getGenericInterfaceType(new ConcreteInterface(), GenericInterface.class, 0));
29     assertEquals(SomeClass.class, Generics.getGenericInterfaceType(new ConcreteInterface(), GenericInterface.class, 1));
30   }
31
32   @Test
33   public void testGetClassType() throws Exception {
34     assertEquals(SomeClass.class, Generics.getGenericClassType(new ConcreteClass(), GenericClass.class, 0));
35   }
36
37   public interface GenericInterface<T1, T2> {
38     T1 type1();
39
40     T2 type2();
41   }
42
43   public static class ConcreteInterface implements GenericInterface<String, SomeClass> {
44     @Override
45     public String type1() {
46       return null;
47     }
48
49     @Override
50     public SomeClass type2() {
51       return null;
52     }
53   }
54
55   public abstract class GenericClass<T> {
56     public abstract T type();
57   }
58
59   public class ConcreteClass extends GenericClass<SomeClass> {
60     @Override
61     public SomeClass type() {
62       return null;
63     }
64   }
65
66   public class SomeClass {
67   }
68 }