Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7628795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:39:53+00:00 2026-05-31T05:39:53+00:00

I have to write a program that takes an Integer and converts it into

  • 0

I have to write a program that takes an Integer and converts it into its English word version.

For example:

Input:  21
Output: twenty one
Input:  110 
Output: one hundred and ten

I need the program to demonstrate TDD so I want to use mocking.

I have written a class that has a function that does the conversion (based on 2 arrays of English words). What I need now to design the program in such a way that I can demonstrate with Easymock.

Therefore, I need create an interface to be the subject of my mock. Can anyone give me any pointers on how I would design my program?

Would this be suitable?

  1. Write a Converter class that has a reference to an interface called ConverterInterface. I could then mock the interface and set it into my Converter class.

Any help is welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:39:54+00:00Added an answer on May 31, 2026 at 5:39 am

    You can demonstrate TDD without mocking. In fact, mocking can confuse people that are new to TDD. I would simply start by test driving the functionality you are trying to develop, and then worry about mocking later. Let’s assume you’ve test driven the numeric to English converter (which it doesn’t appear you have done yet based on your description) and you have a class that looks something like this:

    public class NumberConverterTest { ... }
    
    public class NumberConverter {
      public String toEnglish(int number) { ... }
    }
    

    You are likely to also have some sort of main class:

    public class NumberConverterMain {
      public void main(String[] args) {
        NumberConverter converter = new NumberConverter();
        System.out.println(converter.toEnglish(args[0]);
      }
    }
    

    You have now demonstrated TDD without mocking. In trying to practice TDD the mocking question will invariably come up. In order to demonstrate mocking, you can add some arbitrary business rule around the toEnglish method such as “All requests for numbers larger than 1000 must be logged to the large number department”. Knowing that the large number department is hosted on another server that we don’t want to have a dependency on we can test drive the interface and mock it out.

    public class NumberConverterTest {
      // ..
      @Test public void theLargeNumberDepartmentIsNotifiedForLargeNumbers() {
         LargeNumberDepartment department = new MockLargeNumberDepartment(1000);
         NumberConverter converter = new NumberConverter(department);
         converter.toEnglish(1000);
         assertTrue(department.wasNotifiedWith(1000));
      }
    
      public static MockLargeNumberDepartment implements LargeNumberDepartment {
    
         private int valueRequested;
    
         public void MockLargeNumberDepartment(int threshhold) {
           this.threshold = threshold;
         }
    
         public int notificationThreshold() {
           return this.threshold;
         }
    
         public void largeNumberReceived(int value) {
           valueRequested = value;
         }
    
         public boolean wasNotifiedWith(int value) {
           assertEquals(value, valueRequested);
           return true;
         }
      }
    }
    
    // In NumberConverter.java
    public class NumberConverter {
      public NumberConverter(LargeNumberDepartment department) {
        this.department = department;
      }
    
      public String toEnglish(int value) {
        if(value > department.notificationThreshold())
          department.largeNumberReceived(value);
        return convertIt(value);  
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been assigned wit the task to write a program that takes a
I am trying to write a program that takes an input of of n
I have a C++ program that takes user input for fopen in order to
I'm trying to write a program that takes input of - hexadecimals, octals, and
I'm solving the following kata: Write a program that takes as its first argument
I have to write a program that read from a file that contains the
I have to write a program that sniffs network packets (part1-the simple part). And
I wanted to write a program that test if two files are duplicates (have
I have a Perl program, that needs to use packages (that I also write).
Background: I have a function in my program that takes a set of points

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.