| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 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 | |
@GwtCompatible |
| 27 | |
public class ClassSubject extends Subject<ClassSubject, Class<?>> { |
| 28 | |
public ClassSubject(FailureStrategy failureStrategy, Class<?> o) { |
| 29 | 5 | super(failureStrategy, o); |
| 30 | 5 | } |
| 31 | |
|
| 32 | |
|
| 33 | |
@GwtIncompatible("Reflection. ") |
| 34 | |
public void declaresField(String fieldName) { |
| 35 | 4 | if (getSubject() == null) { |
| 36 | 1 | failureStrategy.fail("Cannot determine a field name from a null class."); |
| 37 | 0 | return; |
| 38 | |
} |
| 39 | |
try { |
| 40 | 3 | ReflectionUtil.getField(getSubject(), fieldName); |
| 41 | 1 | } catch (NoSuchFieldException e) { |
| 42 | 1 | StringBuilder message = new StringBuilder("Not true that "); |
| 43 | 1 | message.append("<").append(getSubject().getSimpleName()).append(">"); |
| 44 | 1 | message.append(" has a field named <").append(fieldName).append(">"); |
| 45 | 1 | failureStrategy.fail(message.toString()); |
| 46 | 2 | } |
| 47 | 2 | } |
| 48 | |
|
| 49 | |
} |