CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/springboot-testing

Spring Boot testing — @WebMvcTest for controllers, @DataJpaTest for repositories, @SpringBootTest only for integration, MockMvc, @MockBean vs @Mock, AssertJ, @Transactional rollback, @ActiveProfiles, TestContainers

93

1.09x
Quality

89%

Does it follow best practices?

Impact

100%

1.09x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-3/

Payment Service Unit Tests

Write unit tests for a Spring Boot service that processes payments. The application has:

  • PaymentService with a method PaymentResult processPayment(PaymentRequest request) that:
    • Validates the payment amount is positive
    • Calls PaymentGateway.charge(amount, cardToken) to process the charge
    • Saves the payment record via PaymentRepository.save(payment)
    • Returns a PaymentResult with status and transaction ID
    • Throws PaymentDeclinedException if the gateway declines the charge
    • Throws IllegalArgumentException if the amount is zero or negative
  • PaymentGateway is an interface for the external payment provider
  • PaymentRepository extends JpaRepository<Payment, Long>

Output

Produce a Java test file at src/test/java/com/example/payments/service/PaymentServiceTest.java.

Test at minimum:

  1. Successful payment returns a PaymentResult with SUCCESS status
  2. Payment with zero amount throws IllegalArgumentException
  3. Declined gateway charge throws PaymentDeclinedException
  4. Successful payment saves the payment record to the repository
  5. Gateway is called with correct amount and card token

Do not produce the application source code -- only the test file.

evals

tile.json