Forked from AdelinGhanaem/SitebricksReplyAssertion.java
Created
November 15, 2012 07:47
-
-
Save mlesikov/4077269 to your computer and use it in GitHub Desktop.
Testing sitebricks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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