Skip to content

Commit

Permalink
Unify use of reparceling error.
Browse files Browse the repository at this point in the history
  • Loading branch information
mg6maciej committed Apr 4, 2015
1 parent bcac6e2 commit fa379ff
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void testWithProtectedCreatorShouldFail() {
ReparcelingResult<WithProtectedCreator> result = reparceler.reparcel(original);
assertSame(original, result.getOriginal());
assertNull(result.getReparceled());
assertTrue(result.getError() instanceof ReparcelingError);
assertNotNull(result.getError());
assertEquals("Missing public static CREATOR field on class WithProtectedCreator.", result.getError().getMessage());
}

Expand All @@ -23,7 +23,7 @@ public void testWithoutCreatorShouldFail() {
ReparcelingResult<WithNonStaticCreator> result = reparceler.reparcel(original);
assertSame(original, result.getOriginal());
assertNull(result.getReparceled());
assertTrue(result.getError() instanceof ReparcelingError);
assertNotNull(result.getError());
assertEquals("Missing public static CREATOR field on class WithNonStaticCreator.", result.getError().getMessage());
}
}
1 change: 0 additions & 1 deletion src/androidTest/java/pl/mg6/testsupport/data/Complex.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public Complex(Simple simple, Hrisey hrisey, List<String> list) {
this.list = list;
}


@Override
public int describeContents() {
return 0;
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/pl/mg6/testsupport/FactoryReparceler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ private static <T extends Parcelable> ReparcelingResult<T> reparcel(Method metho
T original = (T) method.invoke(null);
return Reparceler.reparcel(original, method.getName());
} catch (Throwable error) {
return new ReparcelingResult<>(null, null, false, method.getName(), error);
return new ReparcelingResult<>(null, null, false, method.getName(), createError(method, error));
}
}

private static ReparcelingError createError(Method method, Throwable error) {
String methodName = method.getName();
String className = method.getDeclaringClass().getSimpleName();
String message = String.format("Cannot invoke method %s on class %s.", methodName, className);
return new ReparcelingError(message, error);
}
}
3 changes: 2 additions & 1 deletion src/main/java/pl/mg6/testsupport/Reparceler.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private static <T extends Parcelable> T reparcelImpl(T original) throws Throwabl

private static ReparcelingError createError(Parcelable original, Throwable error) {
String name = original.getClass().getSimpleName();
return new ReparcelingError(String.format("Missing public static CREATOR field on class %s.", name), error);
String message = String.format("Missing public static CREATOR field on class %s.", name);
return new ReparcelingError(message, error);
}
}
6 changes: 3 additions & 3 deletions src/main/java/pl/mg6/testsupport/ReparcelingResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class ReparcelingResult<T extends Parcelable> {
private final T reparceled;
private final boolean areEqual;
private final String methodName;
private final Throwable error;
private final ReparcelingError error;

public ReparcelingResult(T original, T reparceled, boolean areEqual, String methodName, Throwable error) {
public ReparcelingResult(T original, T reparceled, boolean areEqual, String methodName, ReparcelingError error) {
this.original = original;
this.reparceled = reparceled;
this.areEqual = areEqual;
Expand All @@ -34,7 +34,7 @@ public String getMethodName() {
return methodName;
}

public Throwable getError() {
public ReparcelingError getError() {
return error;
}
}

0 comments on commit fa379ff

Please sign in to comment.