Skip to content

Commit

Permalink
Merge pull request #74 from NashTech-Labs/feature/Resolve-code-smells
Browse files Browse the repository at this point in the history
Updated PaymentAggregate test
  • Loading branch information
ankit-mogha authored Jan 16, 2024
2 parents 41ace5b + 1c25585 commit c2f3244
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void on(PaymentCancelledEvent paymentApprovedEvent) {
}

//Hard coded User details
private User getUser() {
public User getUser() {
return User.builder()
.userId("1652")
.firstName("Abid")
Expand All @@ -92,7 +92,7 @@ private User getUser() {
}

//Hard coded payment details
private PaymentDetails getPaymentDetails() {
public PaymentDetails getPaymentDetails() {
return PaymentDetails.builder()
.userId("1652")
.bank("SBI")
Expand All @@ -104,7 +104,7 @@ private PaymentDetails getPaymentDetails() {
.build();
}

private PaymentCancelledEvent buildPaymentCancelEvent(ProcessPaymentCommand processPaymentCommand, String reasonToFailed) {
public PaymentCancelledEvent buildPaymentCancelEvent(ProcessPaymentCommand processPaymentCommand, String reasonToFailed) {
return PaymentCancelledEvent.builder()
.paymentId(processPaymentCommand.getPaymentId())
.orderId(processPaymentCommand.getOrderId())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,87 @@
package com.nashtech.payment.aggregate;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import com.nashtech.common.command.ProcessPaymentCommand;
import com.nashtech.common.event.PaymentApprovedEvent;
import com.nashtech.common.event.PaymentCancelledEvent;
import com.nashtech.common.model.PaymentDetails;
import com.nashtech.common.model.User;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

class PaymentAggregateTest {
/**
* Method under test:
* {@link PaymentAggregate#buildPaymentCancelEvent(ProcessPaymentCommand, String)}
*/
@Test
void testBuildPaymentCancelEvent() {
// Arrange
PaymentAggregate paymentAggregate = new PaymentAggregate();
ProcessPaymentCommand processPaymentCommand = ProcessPaymentCommand.builder()
.basePrice(10.0d)
.brand("Brand")
.orderId("42")
.paymentId("42")
.productId("42")
.quantity(1)
.subTotal(10.0d)
.tax(10.0f)
.total(10.0d)
.totalTax(10.0f)
.userId("42")
.build();

// Act
PaymentCancelledEvent actualBuildPaymentCancelEventResult = paymentAggregate
.buildPaymentCancelEvent(processPaymentCommand, "Just cause");

// Assert
assertEquals("42", actualBuildPaymentCancelEventResult.getOrderId());
assertEquals("42", actualBuildPaymentCancelEventResult.getPaymentId());
assertEquals("42", actualBuildPaymentCancelEventResult.getProductId());
assertEquals("42", actualBuildPaymentCancelEventResult.getUserId());
assertEquals("Just cause", actualBuildPaymentCancelEventResult.getReasonToFailed());
assertEquals(1, actualBuildPaymentCancelEventResult.getQuantity().intValue());
}

/**
* Method under test: {@link PaymentAggregate#getPaymentDetails()}
*/
@Test
void testGetPaymentDetails() {
// Arrange and Act
PaymentDetails actualPaymentDetails = (new PaymentAggregate()).getPaymentDetails();

// Assert
assertEquals("0900987654435443", actualPaymentDetails.getCardNumber());
assertEquals("1652", actualPaymentDetails.getUserId());
assertEquals("SBI", actualPaymentDetails.getBank());
assertEquals(1.0E9d, actualPaymentDetails.getBalanceAmount().doubleValue());
assertEquals(2028, actualPaymentDetails.getValidUntilYear().intValue());
assertEquals(334, actualPaymentDetails.getCvv().intValue());
assertEquals(6, actualPaymentDetails.getValidUntilMonth().intValue());
}

/**
* Method under test: {@link PaymentAggregate#getUser()}
*/
@Test
void testGetUser() {
// Arrange and Act
User actualUser = (new PaymentAggregate()).getUser();

// Assert
assertEquals("1652", actualUser.getUserId());
assertEquals("9087658765", actualUser.getMobileNumber());
assertEquals("Abid", actualUser.getFirstName());
assertEquals("Khan", actualUser.getLastName());
assertEquals("Noida", actualUser.getAddress());
assertEquals("[email protected]", actualUser.getEmailId());
}

/**
* Method under test: {@link PaymentAggregate#PaymentAggregate()}
*/
Expand All @@ -19,11 +91,26 @@ void testNewPaymentAggregate() {
PaymentAggregate actualPaymentAggregate = new PaymentAggregate();

// Assert
PaymentDetails paymentDetails = actualPaymentAggregate.getPaymentDetails();
assertEquals("0900987654435443", paymentDetails.getCardNumber());
assertEquals("1652", paymentDetails.getUserId());
User user = actualPaymentAggregate.getUser();
assertEquals("1652", user.getUserId());
assertEquals("9087658765", user.getMobileNumber());
assertEquals("Abid", user.getFirstName());
assertEquals("Khan", user.getLastName());
assertEquals("Noida", user.getAddress());
assertEquals("SBI", paymentDetails.getBank());
assertEquals("[email protected]", user.getEmailId());
assertNull(actualPaymentAggregate.getBasePrice());
assertNull(actualPaymentAggregate.getQuantity());
assertNull(actualPaymentAggregate.getOrderId());
assertNull(actualPaymentAggregate.getPaymentId());
assertNull(actualPaymentAggregate.getProductId());
assertEquals(1.0E9d, paymentDetails.getBalanceAmount().doubleValue());
assertEquals(2028, paymentDetails.getValidUntilYear().intValue());
assertEquals(334, paymentDetails.getCvv().intValue());
assertEquals(6, paymentDetails.getValidUntilMonth().intValue());
}

/**
Expand Down

0 comments on commit c2f3244

Please sign in to comment.