<commit_before>package me.pagarme;

import me.pagar.model.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

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

public class TransactionTest extends BaseTest {

    private Recipient recipient = new Recipient();
    private SplitRule splitRule = new SplitRule();
    private BankAccount bankAccount;

    private static Integer AMOUNT = 100;
    private static Integer PAID_AMOUNT_PARTIAL = 50;

    @Before
    public void setUp() {
        super.setUp();
        transaction = new Transaction();
    }

    @Test
    public void testCreateAndCaptureTransactionWithOfflineDebitCard() throws Throwable {

        transaction = this.transactionDebitCardCommon("offline");
        transaction.setCapture(true);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.DEBIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
    }

    @Test
    public void testCreateAndAuthorizedTransactionWithOfflineDebitCard() throws Throwable {

        transaction = this.transactionDebitCardCommon("offline");
        transaction.setCapture(false);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.DEBIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.AUTHORIZED);
    }

    @Test
    public void testCreateAndCaptureTransactionWithOnlineDebitCard() throws Throwable {

        transaction = this.transactionDebitCardCommon("online");
        transaction.setCapture(true);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.DEBIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
    }

    @Test
    public void testCreateAndAuthorizedTransactionWithOnlineDebitCard() throws Throwable {

        transaction = this.transactionDebitCardCommon("online");
        transaction.setCapture(false);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.DEBIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.AUTHORIZED);
    }

    @Test
    public void testCreateAndCaptureTransactionWithSoftDescriptor() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setSoftDescriptor("API Test");
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.CREDIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
        Assert.assertEquals(transaction.getSoftDescriptor(), "API Test");
    }

    @Test
    public void testCreateAndCaptureTransactionWithCreditCardWithoutGoingThroughFraud() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setCapture(true);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.CREDIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
    }

    @Test
    public void testCreateAndCaptureTransactionMetaData() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setCapture(true);

        Map<String, Object> metadata =  new HashMap<String, Object>();
        metadata.put("metadata1", "value1");
        metadata.put("metadata2", "value2");

        transaction.setMetadata(metadata);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.CREDIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
    }
    
    @Test
    public void testCreateAndCaptureTransactionAntifraudMetaData() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setCapture(true);

        Map<String, Object> antifraudMetadata =  new HashMap<String, Object>();
        antifraudMetadata.put("metadata1", "value1");
        antifraudMetadata.put("metadata2", "value2");

        transaction.setAntifraudMetadata(antifraudMetadata);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.CREDIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
    }

    @Test
    public void testCreateAndCaptureTransactionMetaDataInCapture() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setCapture(false);
        transaction.save();

        Map<String, Object> metadata =  new HashMap<String, Object>();
        metadata.put("metadata1", "value1");
        metadata.put("metadata2", "value2");
        transaction.setMetadata(metadata);

        transaction.capture(AMOUNT);
<commit_msg>Refactored test<commit_after>package me.pagarme;

import me.pagar.model.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

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

public class TransactionTest extends BaseTest {

    private Recipient recipient = new Recipient();
    private SplitRule splitRule = new SplitRule();
    private BankAccount bankAccount;

    private static Integer AMOUNT = 100;
    private static Integer PAID_AMOUNT_PARTIAL = 50;

    @Before
    public void setUp() {
        super.setUp();
        transaction = new Transaction();
    }

    @Test
    public void testCreateAndCaptureTransactionWithOfflineDebitCard() throws Throwable {

        transaction = this.transactionDebitCardCommon("offline");
        transaction.setCapture(true);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.DEBIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
    }

    @Test
    public void testCreateAndAuthorizedTransactionWithOfflineDebitCard() throws Throwable {

        transaction = this.transactionDebitCardCommon("offline");
        transaction.setCapture(false);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.DEBIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.AUTHORIZED);
    }

    @Test
    public void testCreateAndCaptureTransactionWithOnlineDebitCard() throws Throwable {

        transaction = this.transactionDebitCardCommon("online");
        transaction.setCapture(true);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.DEBIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
    }

    @Test
    public void testCreateAndAuthorizedTransactionWithOnlineDebitCard() throws Throwable {

        transaction = this.transactionDebitCardCommon("online");
        transaction.setCapture(false);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.DEBIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.AUTHORIZED);
    }

    @Test
    public void testCreateAndCaptureTransactionWithSoftDescriptor() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setSoftDescriptor("API Test");
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.CREDIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
        Assert.assertEquals(transaction.getSoftDescriptor(), "API Test");
    }

    @Test
    public void testCreateAndCaptureTransactionWithCreditCardWithoutGoingThroughFraud() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setCapture(true);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.CREDIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
    }

    @Test
    public void testCreateAndCaptureTransactionMetaData() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setCapture(true);

        Map<String, Object> metadata =  new HashMap<String, Object>();
        metadata.put("metadata1", "value1");
        metadata.put("metadata2", "value2");

        transaction.setMetadata(metadata);
        transaction.save();

        Assert.assertEquals(transaction.getPaymentMethod(), Transaction.PaymentMethod.CREDIT_CARD);
        Assert.assertEquals(transaction.getStatus(), Transaction.Status.PAID);
    }
    
    @Test
    public void testCreateAndCaptureTransactionAntifraudMetaData() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setCapture(true);

        Map<String, Object> antifraudMetadata =  new HashMap<String, Object>();
        antifraudMetadata.put("metadata1", "value1");
        antifraudMetadata.put("metadata2", "value2");

        transaction.setAntifraudMetadata(antifraudMetadata);
        transaction.save();

        Assert.assertEquals(transaction.getAntifraudMetadata().get("metadata1"), "value1");
        Assert.assertEquals(transaction.getAntifraudMetadata().get("metadata2"), "value2");
        
    }

    @Test
    public void testCreateAndCaptureTransactionMetaDataInCapture() throws Throwable {

        transaction = this.transactionCreditCardCommon();
        transaction.setCapture(false);
        transaction.save();

        Map<String, Object> metadata =  new HashMap<String, Object>();
        metadata.put("metadata1", "value1");
        metadata.put("metadata2", "value2");
        transaction.setMetadata(metadata);

        transaction.capture(AMOUNT);

{'fraction_non_alphanumeric': 0.10074853327938499, 'fraction_numerical': 0.0038438195427877805, 'mean_word_length': 3.834718826405868, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6029454', 'n_tokens_mistral': 2514, 'n_tokens_neox': 2370, 'n_words': 421}