Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started

Writing Test Cases Without Mocks

HardExecution00:00
Practice interviewer
In session
5 left
00:00

Whenever you're ready, walk me through how you'd approach this.

You need to log in / sign up to chat or submit.

Problem

You're interviewing for a Software Engineer role at Zemoso Technologies, working on a client's order pricing service. The interviewer hands you the classes below and explains that the pricing logic calls static utility methods that can throw exceptions on bad input.

public class OrderPricingService {

    public double calculateFinalPrice(Order order) {
        double basePrice = order.getBasePrice();
        double tax = TaxCalculator.calculate(order.getRegion(), basePrice);
        double converted = CurrencyConverter.convert(basePrice + tax, order.getCurrency());
        return converted;
    }
}

public class TaxCalculator {
    public static double calculate(String region, double amount) {
        if (region == null) {
            throw new IllegalArgumentException("Region is required");
        }
        double rate = TaxRates.getRate(region);
        return amount * rate;
    }
}

public class CurrencyConverter {
    public static double convert(double amount, String currency) {
        if (!ExchangeRates.isSupported(currency)) {
            throw new UnsupportedCurrencyException(currency);
        }
        return amount * ExchangeRates.getRate(currency);
    }
}

How would you write test cases that cover both the happy path and the exception paths of calculateFinalPrice, without using Mockito or PowerMock, and without changing the logic inside TaxCalculator or CurrencyConverter? You may refactor as long as behavior stays the same. Explain your approach in words.