Skip to content

Commit

Permalink
Possibility to get only results with issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mg6maciej committed Apr 4, 2015
1 parent 7ff7346 commit 1847ca0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import junit.framework.TestCase;

import java.util.List;

import pl.mg6.testsupport.data.Simple;
import pl.mg6.testsupport.factory.SimpleFactory;

public class FactoryReparcelerTestCase extends TestCase {

private final FactoryReparceler reparceler = new FactoryReparceler();
private final FactoryReparceler factoryReparceler = new FactoryReparceler();

public void testSimpleParcelableShouldBeEqual() {
ReparcelingResultList<Simple> resultList = reparceler.reparcel(SimpleFactory.class, Simple.class);
ReparcelingResultList<Simple> resultList = factoryReparceler.reparcel(SimpleFactory.class, Simple.class);
for (ReparcelingResult<Simple> result : resultList) {
assertNotNull(result.getOriginal());
assertNotNull(result.getReparceled());
Expand All @@ -23,10 +21,15 @@ public void testSimpleParcelableShouldBeEqual() {
}

public void testFactoryReparcelerShouldFindAllMethods() {
ReparcelingResultList<Simple> resultList = reparceler.reparcel(SimpleFactory.class, Simple.class);
ReparcelingResultList<Simple> resultList = factoryReparceler.reparcel(SimpleFactory.class, Simple.class);
assertEquals(3, resultList.size());
assertEquals("withZero", resultList.get(2).getMethodName());
assertEquals("withPerfectNumber", resultList.get(1).getMethodName());
assertEquals("withMaxValue", resultList.get(0).getMethodName());
assertEquals("withPerfectNumber", resultList.get(1).getMethodName());
assertEquals("withZero", resultList.get(2).getMethodName());
}

public void testFacotryReparcelerAllShouldBeEqual() {
ReparcelingResultList<Simple> resultList = factoryReparceler.reparcel(SimpleFactory.class, Simple.class);
assertTrue(resultList.areAllEqual());
}
}
2 changes: 1 addition & 1 deletion src/main/java/pl/mg6/testsupport/ReparcelingError.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public final class ReparcelingError extends RuntimeException {

public ReparcelingError(String detailMessage, Throwable throwable) {
ReparcelingError(String detailMessage, Throwable throwable) {
super(detailMessage, throwable);
}
}
2 changes: 1 addition & 1 deletion src/main/java/pl/mg6/testsupport/ReparcelingResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ReparcelingResult<T extends Parcelable> {
private final String methodName;
private final ReparcelingError error;

public ReparcelingResult(T original, T reparceled, boolean areEqual, String methodName, ReparcelingError error) {
ReparcelingResult(T original, T reparceled, boolean areEqual, String methodName, ReparcelingError error) {
this.original = original;
this.reparceled = reparceled;
this.areEqual = areEqual;
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/pl/mg6/testsupport/ReparcelingResultList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@

import android.os.Parcelable;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ReparcelingResultList<T extends Parcelable> implements Iterable<ReparcelingResult<T>> {

private final List<ReparcelingResult<T>> results;

public ReparcelingResultList(List<ReparcelingResult<T>> results) {
ReparcelingResultList(List<ReparcelingResult<T>> results) {
this.results = results;
}

public boolean areAllEqual() {
return getIssues().size() == 0;
}

public ReparcelingResult<T> get(int location) {
return results.get(location);
}

public ReparcelingResultList<T> getIssues() {
List<ReparcelingResult<T>> issues = new ArrayList<>();
for (ReparcelingResult<T> result : results) {
if (!result.areEqual()) {
issues.add(result);
}
}
return new ReparcelingResultList<>(issues);
}

@Override
public Iterator<ReparcelingResult<T>> iterator() {
return results.iterator();
Expand Down

0 comments on commit 1847ca0

Please sign in to comment.