Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mlesikov/4077269 to your computer and use it in GitHub Desktop.
Save mlesikov/4077269 to your computer and use it in GitHub Desktop.
Testing sitebricks
/**
* @author Adelin Ghanayem [email protected]
*/
public class SitebricksReplyAssertion {
public static <T> void assertIsRepliedWith(Reply<T> reply, T expected) {
assertFieldValue("entity", reply, expected);
}
public static <T> void assertThatReplyStatusIs(Reply<T> reply, int expected) {
assertFieldValue("status", reply, expected);
}
private static <T> void assertFieldValue(String fieldName, Reply reply, T expected) {
Field field = null;
try {
field = reply.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
T actual = (T) field.get(reply);
assert actual != null;
assertThat(actual, is(equalTo(expected)));
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment