| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SubjectFactory |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright (c) 2011 David Saff | |
| 3 | * Copyright (c) 2011 Christian Gruber | |
| 4 | * | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 11 | * Unless required by applicable law or agreed to in writing, software | |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 | * See the License for the specific language governing permissions and | |
| 15 | * limitations under the License. | |
| 16 | */ | |
| 17 | package org.truth0.subjects; | |
| 18 | ||
| 19 | ||
| 20 | import org.truth0.FailureStrategy; | |
| 21 | import org.truth0.util.ReflectionUtil; | |
| 22 | ||
| 23 | import com.google.common.annotations.GwtCompatible; | |
| 24 | import com.google.common.annotations.GwtIncompatible; | |
| 25 | ||
| 26 | /** | |
| 27 | * A custom subject factory which will return a FooSubject (which | |
| 28 | * is a Subject<Foo>). | |
| 29 | * | |
| 30 | * @author Christian Gruber (cgruber@israfil.net) | |
| 31 | */ | |
| 32 | @GwtCompatible | |
| 33 | public abstract class SubjectFactory<S extends Subject<S,T>, T> { | |
| 34 | ||
| 35 | @GwtIncompatible("reflection") | |
| 36 | private static final int SUBJECT_TYPE_PARAMETER = 0; | |
| 37 | ||
| 38 | 6 | @GwtIncompatible("reflection") |
| 39 | private final Class<S> type = | |
| 40 | (Class<S>)ReflectionUtil.typeParameter(getClass(), SUBJECT_TYPE_PARAMETER); | |
| 41 | ||
| 42 | 12 | public SubjectFactory() {} |
| 43 | ||
| 44 | public abstract S getSubject(FailureStrategy fs, T that); | |
| 45 | ||
| 46 | @GwtIncompatible("reflection") | |
| 47 | public Class<S> getSubjectClass() { | |
| 48 | 15 | return type; |
| 49 | } | |
| 50 | ||
| 51 | } | |
| 52 |