DEV Community

Marcin Parśniak
Marcin Parśniak

Posted on

Revenue test (JUnit5) - Finovara

Hello!

After the latest update to my project, I decided it was the perfect time to finally start writing tests for Finovara.

So far, I've written tests for the main methods.
On average, I run 2-3 tests per method, which seems like a good compromise. I cover both the happy path and a few edge cases and alternate flows—basically, I try to make sure everything works as expected, regardless of the situation.

Overall, I'm aiming for 70-80% code coverage, though this may change as I add more tests and improve what I already have.

Example of a simple test:

@Test
void shouldAddRevenueSuccessfully() {
        RevenueDTO dto = new RevenueDTO(null, null, new BigDecimal("100"), RevenueCategory.SALARY, null, "test income");
        String email = "test@test.com";
        User user = new User();

        when(timeConfig.clock()).thenReturn(Clock.systemDefaultZone());
        when(userManagerService.getUserByEmailOrThrow(email)).thenReturn(user);

        revenueService.addRevenue(dto, email);

        verify(walletService).addBalanceToWallet(email, dto.amount());
        verify(revenueActivityService).createRevenueActivity(eq(email), eq(RevenueActivityType.ADDED_REVENUE), any(Revenue.class));
        verify(revenueRepository).save(any(Revenue.class));
        verify(revenueScoringService).recalculateScore(email);
        verify(autoPaymentsService).handleRevenuePiggyBankAutomation(email, dto.amount(), AutoPaymentsMode.APPLY);
    }
Enter fullscreen mode Exit fullscreen mode

Next, I plan to write expense tests. I'll see how it goes

Thanks for reading, and please visit my GitHub:

GitHub logo M4rc1nek / finovara-backend

Backend service for a personal finance management application

💰 Finovara — Backend

Backend REST API for a personal finance management application built with Java 25 and Spring Boot 4.


📖 About the Project

Finovara is a personal finance platform designed to help users take full control of their money. The backend exposes a secure REST API that powers tracking of income and expenses, budget management, savings goals, and financial reporting — all wrapped in a bank-grade security model based on JWT authentication.

The application is designed with scalability in mind and is fully containerized via Docker, with separate production and test database environments managed through Docker Compose.


🎯 Key Features

  • 🔐 Authentication & Authorization — JWT-based stateless security with Spring Security; access and refresh token flow with device/user-agent detection
  • 💸 Income & Expense Tracking — full CRUD for financial operations with category tagging
  • 📊 Statistics & Reports — aggregated financial summaries, spending trends, and exportable PDF reports
  • 🏦…




Top comments (0)