Skip to content

Commit

Permalink
Modified NotificationUrl test. (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
OGKevin committed Nov 22, 2017
1 parent bae3983 commit c57eea2
Showing 1 changed file with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public class NotificationUrlTest extends BunqSdkTestBase {
private static final String GETTER_PAYMENT = "getPayment";
private static final String GETTER_BUNQ_ME_TAB = "getBunqMeTab";
private static final String GETTER_CHAT_MESSAGE_ANNOUNCEMENT = "getChatMessageAnnouncement";
private static final String GETTER_CHAT_MESSAGE = "getChatMessage";
private static final String GETTER_DRAFT_PAYMENT = "getDraftPayment";
private static final String GETTER_MASTER_CARD_ACTION = "getMasterCardAction";
private static final String GETTER_MONETARY_ACCOUNT_BANK = "getMonetaryAccountBank";
private static final String GETTER_MONETARY_ACCOUNT = "getMonetaryAccount";
private static final String GETTER_PAYMENT_BATCH = "getPaymentBatch";
private static final String GETTER_REQUEST_INQUIRY = "getRequestInquiry";
private static final String GETTER_REQUEST_RESPONSE = "getRequestResponse";
Expand Down Expand Up @@ -62,14 +64,16 @@ public class NotificationUrlTest extends BunqSdkTestBase {
private void executeNotificationUrlTest(
String expectedJsonFileName,
String classNameExpected,
String referencedObjectGetterName
String referencedObjectGetterName,
String subClassExpectedName,
String subClassGetterName
) throws FileNotFoundException,
NoSuchMethodException,
InvocationTargetException,
IllegalAccessException,
ClassNotFoundException {
JsonReader jsonReader = new JsonReader(new FileReader(expectedJsonFileName));
NotificationUrl notificationUrl = new Gson().fromJson(jsonReader, TYPE_NOTIFICATION_URL);
NotificationUrl notificationUrl = BunqModel.fromJsonReader(NotificationUrl.class, jsonReader);

assertNotNull(notificationUrl);
assertNotNull(notificationUrl.getObject());
Expand All @@ -82,6 +86,33 @@ private void executeNotificationUrlTest(
assertNotNull(model);
assertNotNull(referencedModel);
assertTrue(Class.forName(classNameExpected).isInstance(referencedModel));

if (subClassExpectedName != null && subClassGetterName != null) {
Object subClass = referencedModel.getClass().getDeclaredMethod(subClassGetterName).invoke(
referencedModel
);

assertNotNull(subClass);
assertTrue(Class.forName(subClassExpectedName).isInstance(subClass));
}
}

private void executeNotificationUrlTest(
String expectedJsonFileName,
String classNameExpected,
String referencedObjectGetterName
) throws InvocationTargetException,
FileNotFoundException,
ClassNotFoundException,
IllegalAccessException,
NoSuchMethodException {
this.executeNotificationUrlTest(
expectedJsonFileName,
classNameExpected,
referencedObjectGetterName,
null,
null
);
}

@Test
Expand Down Expand Up @@ -115,6 +146,8 @@ public void chatMessageAnnouncementModelTest() throws InvocationTargetException,
NoSuchMethodException {
executeNotificationUrlTest(
JSON_PATH_CHAT_MESSAGE_ANNOUNCEMENT_MODEL,
ChatMessage.class.getName(),
GETTER_CHAT_MESSAGE,
ChatMessageAnnouncement.class.getName(),
GETTER_CHAT_MESSAGE_ANNOUNCEMENT
);
Expand Down Expand Up @@ -151,6 +184,8 @@ public void monetaryAccountModelTest() throws InvocationTargetException, FileNot
NoSuchMethodException {
executeNotificationUrlTest(
JSON_PATH_MONETARY_ACCOUNT_BANK_MODEL,
MonetaryAccount.class.getName(),
GETTER_MONETARY_ACCOUNT,
MonetaryAccountBank.class.getName(),
GETTER_MONETARY_ACCOUNT_BANK
);
Expand Down

0 comments on commit c57eea2

Please sign in to comment.