The following document contains the results of PMD's CPD 4.3.
| File | Line |
|---|---|
| org/truth0/TestVerb.java | 50 |
| org/truth0/gwtemul/org/truth0/TestVerb.java | 42 |
return new ClassSubject(getFailureStrategy(), target);
}
public IntegerSubject that(Long target) {
return new IntegerSubject(getFailureStrategy(), target);
}
public IntegerSubject that(Integer target) {
return new IntegerSubject(getFailureStrategy(), target);
}
public BooleanSubject that(Boolean target) {
return new BooleanSubject(getFailureStrategy(), target);
}
public StringSubject that(String target) {
return new StringSubject(getFailureStrategy(), target);
}
public <T, C extends Iterable<T>> IterableSubject<? extends IterableSubject<?, T, C>, T, C> that(Iterable<T> target) {
return IterableSubject.create(getFailureStrategy(), target);
}
public <T, C extends Collection<T>> CollectionSubject<? extends CollectionSubject<?, T, C>, T, C> that(Collection<T> target) {
return CollectionSubject.create(getFailureStrategy(), target);
}
public <T, C extends List<T>> ListSubject<? extends ListSubject<?, T, C>, T, C> that(List<T> target) {
return ListSubject.create(getFailureStrategy(), target);
}
public <T, C extends List<T>> ListSubject<? extends ListSubject<?, T, C>, T, C> that(T[] target) {
return that(Arrays.asList(target));
}
public <K, V, M extends Map<K, V>> MapSubject<? extends MapSubject<?, K, V, M>, K, V, M> that(Map<K, V> target) {
return MapSubject.create(getFailureStrategy(), target);
}
} | |
| File | Line |
|---|---|
| org/truth0/gwtemul/org/truth0/subjects/Subject.java | 29 |
| org/truth0/subjects/Subject.java | 37 |
public class Subject<S extends Subject<S,T>,T> {
protected final FailureStrategy failureStrategy;
private final T subject;
public Subject(FailureStrategy failureStrategy, T subject) {
this.failureStrategy = failureStrategy;
this.subject = subject;
}
public void is(T other) {
if (getSubject() == null) {
if(other != null) {
fail("is", other);
}
} else {
if (!getSubject().equals(other)) {
fail("is", other);
}
}
}
public void isNull() {
if (getSubject() != null) {
failWithoutSubject("is null");
}
}
public void isNotNull() {
if (getSubject() == null) {
failWithoutSubject("is not null");
}
}
public void isEqualTo(Object other) {
if (getSubject() == null) {
if(other != null) {
fail("is equal to", other);
}
} else {
if (!getSubject().equals(other)) {
fail("is equal to", other);
}
}
}
public void isNotEqualTo(Object other) {
if (getSubject() == null) {
if(other == null) {
fail("is not equal to", (Object)null);
}
} else {
if (getSubject().equals(other)) {
fail("is not equal to", other);
}
}
} | |
| File | Line |
|---|---|
| org/truth0/gwtemul/org/truth0/subjects/Subject.java | 84 |
| org/truth0/subjects/Subject.java | 106 |
}
}
protected T getSubject() {
return subject;
}
protected TestVerb check() {
return new TestVerb(failureStrategy);
}
/**
* Assembles a failure message and passes such to the FailureStrategy
* @param verb the act being asserted
* @param messageParts the expectations against which the subject is compared
*/
protected void fail(String verb, Object... messageParts) {
StringBuilder message = new StringBuilder("Not true that ");
message.append("<").append(getSubject()).append("> ").append(verb);
for (Object part : messageParts) {
message.append(" <").append(part).append(">");
}
failureStrategy.fail(message.toString());
}
/**
* Assembles a failure message and passes such to the FailureStrategy
* @param verb the act being asserted
* @param messageParts the expectations against which the subject is compared
*/
protected void failWithBadResults(String verb, Object expected, String failVerb, Object actual) {
StringBuilder message = new StringBuilder("Not true that ");
message.append("<").append(getSubject()).append("> ").append(verb);
message.append(" <").append(expected).append(">");
message.append(" it ").append(failVerb);
message.append(" <").append(actual).append(">");
failureStrategy.fail(message.toString());
}
protected void failWithoutSubject(String verb) {
StringBuilder message = new StringBuilder("Not true that ");
message.append("the subject ").append(verb);
failureStrategy.fail(message.toString());
} | |
| File | Line |
|---|---|
| org/truth0/AbstractVerb.java | 10 |
| org/truth0/gwtemul/org/truth0/AbstractVerb.java | 6 |
public class AbstractVerb {
private final FailureStrategy failureStrategy;
public AbstractVerb(FailureStrategy failureStrategy) {
this.failureStrategy = failureStrategy;
}
protected FailureStrategy getFailureStrategy() {
return failureStrategy;
}
/**
* Triggers the failure strategy with an empty failure message
*/
public void fail() {
failureStrategy.fail("");
}
/**
* Triggers the failure strategy with the given failure message
*/
public void fail(String message) {
failureStrategy.fail(message);
}
/**
* The recommended method of extension of Truth to new types, which is
* documented in {@link DelegationTest }.
*
* @see DelegationTest
* @param factory a SubjectFactory<S, T> implementation
* @returns A custom verb for the type returned by the SubjectFactory
*/
public <S extends Subject<S,T>, T, SF extends SubjectFactory<S, T>>
DelegatedVerb<S, T> about(SF factory) {
return new DelegatedVerb<S, T>(getFailureStrategy(), factory);
}
/**
* A special Verb implementation which wraps a SubjectFactory
*/
public static class DelegatedVerb<S extends Subject<S,T>, T>
extends AbstractVerb {
private final SubjectFactory<S, T> factory;
public DelegatedVerb(FailureStrategy fs, SubjectFactory<S, T> factory) {
super(fs);
this.factory = factory;
}
public S that(T target) {
return factory.getSubject(getFailureStrategy(), target);
}
} | |