Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA The requirements for the test cases follow. Define JUnit test cases to check each of the following rules:Any lead can be assigned to any

JAVA

The requirements for the test cases follow.

Define JUnit test cases to check each of the following rules:Any lead can be assigned to any online user

Include cases for both a lead being unassigned and assigned. The assertion should confirm that the lead is not re-assigned

Include a case where no user is online.

By Location, with a Specific User: Leads from a particular country must be assigned to a specific user

It is usually best to start with the good scenario that you would want to run to demo the application to a client. Here, have a lead from the desired country and have the desired user be online

Add cases with leads from the wrong country and with the desired user being offline. The assertions should confirm that assignments are not made

By Industry, with a Group of User: Leads from a particular industry are assigned to one of a group of users

Include cases where there are leads from the desired industry as well as leads from other industries

Include cases with multiple leads that show that leads are assigned to users in a round-robin order

Write code to cover these cases so they pass. [One common error people make when they start with unit tests is to write tests in a way that you know will fail. You want to get all the test cases to pass.]

For the criteria, you can choose to write classes that implement the Predicate and BiConsumer interfaces, or you can write lambdas that satisfy those interfaces, or you can choose a mix of the two approaches.

If you write lambdas, that code is graded as part of the source code vs. the test case code.

You do not need to update the main program to use rules.

LEAD.JAVA

package crm;

import java.util.*;

public class Lead {

private String leadName;

private String emailAddr;

private String country;

private String industry;

private User assignUser;

//lead constructor

public Lead(String leadName, String email, String country, String industry) {

this.leadName = leadName;

this.emailAddr = email;

this.country = country;

this.industry = industry;

}

//name//

public void setName(String name) {

this.leadName = name;

}

public String getName() {

return leadName;

}

//email //

public void setEmail(String Email) {

this.emailAddr = Email;

}

public String getEmail() {

return emailAddr;

}

//country //

public void setCountry(String Country) {

this.country = Country;

}

public String getCountry() {

return country;

}

//industry getter and setter//

public void setIndustry(String Industry) {

this.industry = Industry;

}

public String getIndustry() {

return industry;

}

//User getter and setter for the assigning a user to a lead

public void setUser(User assignedUser) {

this.assignUser = assignedUser;

}

public User getUser() {

return assignUser;

}

}

USER.java

public class User {

private String name;

private boolean isOnline;

private List assignedLeads;

public User(String name, boolean isOnline) {

this.name = name;

this.isOnline = isOnline;

this.assignedLeads = new ArrayList<>();

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public boolean isOnline() {

return isOnline;

}

public void setOnline(boolean online) {

isOnline = online;

}

public List getAssignedLeads() {

return assignedLeads;

}

AssignLeads.java

public class AssignLeads {

private List leads;

private List users;

public AssignLeads() {

this.leads = new ArrayList<>();

this.users = new ArrayList<>();

}

public void addLead(Lead lead) {

leads.add(lead);

}

public void addUser(User user) {

users.add(user);

}

public void assignLeads() {

for (Lead lead : leads) {

User user = getAvailableUser();

if (user != null) {

user.getAssignedLeads().add(lead);

lead.setAssignedUser(user);

}

}

}

private User getAvailableUser() {

for (User user : users) {

if (user.isOnline() && user.getAssignedLeads().size() < 2) {

return user;

}

}

return null;

}

public void displayLeads() {

System.out.println("Name Country Email Assigned User");

for (Lead lead : leads) {

System.out.println(lead.getName() + " " + lead.getCountry() + " " + lead.getEmail() + " " + (lead.getAssignedUser() != null ? lead.getAssignedUser().getName() : ""));

}

}

public static void main(String[] args) {

AssignLeads assignLeads = new AssignLeads();

Scanner scanner = new Scanner(System.in);

int cmd = -1;

while (cmd != 0) {

System.out.println("0. Quit");

System.out.println("1. Add a lead");

System.out.println("2. Add a user");

System.out.println("3. Assign leads");

System.out.println("4. Display leads");

System.out.print("Please choose a cmd (0-4): ");

cmd = scanner.nextInt();

if (cmd == 1) {

System.out.print("Please enter a name for the lead: ");

String name = scanner.next();

System.out.print("Please enter an email contact for the lead: ");

String email = scanner.next();

System.out.print("Please enter the country where the lead is located: ");

String country = scanner.next();

Lead lead = new Lead(name, email, country,industry);

assignLeads.addLead(lead);

} else if (cmd == 2) {

System.out.print("Please enter a name for the user: ");

String name = scanner.next();

System.out.print("Is the user online? (true/false) ");

boolean isOnline = scanner.nextBoolean();

User user = new User(name, isOnline);

assignLeads.addUser(user);

} else if (cmd == 3) {

assignLeads.assignLeads();

} else if (cmd == 4) {

assignLeads.displayLeads();

}

}

}

}

RULE.JAVA

import java.util.function.BiConsumer;

import java.util.function.Predicate;

public class Rule {

private String ruleName;

private Predicate leadPredicate;

private Predicate userPredicate;

private BiConsumer action;

public Rule(String ruleName, Predicate leadPredicate, Predicate userPredicate,

BiConsumer action) {

this.ruleName = ruleName;

this.leadPredicate = leadPredicate;

this.userPredicate = userPredicate;

this.action = action;

}

public boolean canApply(Lead lead, User user) {

return leadPredicate.test(lead) && userPredicate.test(user);

}

public void execute(Lead lead, User user) {

if (canApply(lead, user)) {

action.accept(lead, user);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions