package com.balancedpayments;


import com.balancedpayments.errors.HTTPError;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;

public class DisputeTest extends BaseTest {

    @Test
    public void testDispute() throws HTTPError, InterruptedException {
        Customer customer = createPersonCustomer();

        Map<String, Object> cardPayload = new HashMap<String, Object>();
        cardPayload.put("number", "6500000000000002");
        cardPayload.put("cvv", "123");
        cardPayload.put("expiration_month", 12);
        cardPayload.put("expiration_year", 3000);

        Card card = new Card(cardPayload);
        card.save();

        card.associateToCustomer(customer);

        HashMap<String, Object> payload = new HashMap<String, Object>();
        payload.put("amount", 100000);
        payload.put("description", "Donuts");

        String debit_href = card.debit(payload).href;
        Dispute dispute = null;

        for (int i = 0; i <= 100; i++) {
            Debit debit = new Debit(debit_href);
            if (debit.dispute != null) {
                dispute = debit.dispute;
                break;
            }
            System.out.println("polling disputes...");
            Thread.sleep(10000);
        }
        
        assertNotNull(dispute);
        assertEquals(100000, dispute.amount.intValue());
        assertEquals("fraud", dispute.reason);
        assertEquals("pending", dispute.status);

        assertNotNull(dispute.amount);
        assertNotNull(dispute.created_at);
        assertNotNull(dispute.currency);
        assertNotNull(dispute.href);
        assertNotNull(dispute.id);
        assertNotNull(dispute.initiated_at);
        assertNotNull(dispute.transaction);
        assertNotNull(dispute.meta);
        assertNotNull(dispute.reason);
        assertNotNull(dispute.respond_by);
        assertNotNull(dispute.status);
        assertNotNull(dispute.updated_at);
        assertNotNull(dispute.events);
    }
}

@@ -200,34 +200,40 @@
 org.
-junit.Assert.assertNotNull
+hamcrest.CoreMatchers.instanceOf
 ;%0A%0Ap
@@ -1541,39 +1541,38 @@
 %0A%0A        assert
-NotNull
+Equals
 (dispute.amount)
@@ -1570,16 +1570,37 @@
 e.amount
+.toString(), %22100000%22
 );%0A     
@@ -1643,39 +1643,38 @@
 ;%0A        assert
-NotNull
+Equals
 (dispute.currenc
@@ -1674,16 +1674,23 @@
 currency
+, %22USD%22
 );%0A     
@@ -1690,39 +1690,36 @@
 ;%0A        assert
-NotNull
+True
 (dispute.href);%0A
@@ -1711,24 +1711,49 @@
 dispute.href
+.contains(%22/disputes/DT%22)
 );%0A        a
@@ -1749,39 +1749,36 @@
 ;%0A        assert
-NotNull
+True
 (dispute.id);%0A  
@@ -1772,16 +1772,33 @@
 spute.id
+.startsWith(%22DT%22)
 );%0A     
@@ -1843,39 +1843,36 @@
 ;%0A        assert
-NotNull
+That
 (dispute.transac
@@ -1879,45 +1879,33 @@
 tion
-);%0A        assertNotNull(dispute.meta
+, instanceOf(Debit.class)
 );%0A 
@@ -1909,39 +1909,38 @@
 ;%0A        assert
-NotNull
+Equals
 (dispute.reason)
@@ -1930,32 +1930,41 @@
 s(dispute.reason
+, %22fraud%22
 );%0A        asser
@@ -1999,39 +1999,38 @@
 ;%0A        assert
-NotNull
+Equals
 (dispute.status)
@@ -2028,16 +2028,27 @@
 e.status
+, %22pending%22
 );%0A     
@@ -2091,39 +2091,36 @@
 ;%0A        assert
-NotNull
+That
 (dispute.events)
@@ -2118,16 +2118,52 @@
 e.events
+, instanceOf(Event.Collection.class)
 );%0A    %7D

edit dispute assertions