Q.1.4 Make use of a class named EstateAgent that contains methods to calculate estate agent
sales, estate agent commission, and the top-performing estate agent. The EstateAgent
class must implement an IEstateAgent interface that contains the following:
public interface IEstateAgent {
double EstateAgentSales(double[] propertySales);
double EstateAgentCommission(double propertySales);
int TopEstateAgent(double[] totalSales);
}
Q.1.5 You are required to write unit tests for the application. Create a test package within the
application you created, which will contain the necessary unit tests.
You are required to write the following unit tests:
Test Name Test Purpose
CalculateTotalSales_ReturnsTotalSales() To supply the property sales to the
estate agent sales method. The test
will determine that the correct total
sales value is returned from the estate
agent sales method.
CalculateTotalCommission_ReturnsCommission() To supply a total property sales
amount to the estate agent
commission method. The test will
determine that the correct estate
agent commission has been
calculated.
TopAgent_ReturnsTopPosition() To supply total sales for each estate
agent to the top estate agent method.
The test will determine the top selling
total property sales for the estate
agent..include import method
1 answer
```java
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class EstateAgentTest {
@Test
public void calculateTotalSales_ReturnsTotalSales() {
EstateAgent estateAgent = new EstateAgent();
double[] propertySales = {100000, 150000, 200000};
double expectedTotalSales = 450000;
double actualTotalSales = estateAgent.EstateAgentSales(propertySales);
assertEquals(expectedTotalSales, actualTotalSales, 0);
}
@Test
public void calculateTotalCommission_ReturnsCommission() {
EstateAgent estateAgent = new EstateAgent();
double propertySales = 100000;
double expectedCommission = 3000;
double actualCommission = estateAgent.EstateAgentCommission(propertySales);
assertEquals(expectedCommission, actualCommission, 0);
}
@Test
public void topAgent_ReturnsTopPosition() {
EstateAgent estateAgent = new EstateAgent();
double[] totalSales = {200000, 150000, 100000, 250000};
int expectedTopPosition = 3;
int actualTopPosition = estateAgent.TopEstateAgent(totalSales);
assertEquals(expectedTopPosition, actualTopPosition);
}
}
```
Make sure to import the necessary classes and methods for the unit tests. In this example, we are using the JUnit framework.