
Write Unit Test Methods for the code snippets below:
package InventoryManagement;
/**
* AddCommand
*/
public class AddProductCommand extends Command
{
//TODO: add necessary fields to this class
public AddProductCommand(ProductCatalog productCatalog, User loggedOnUser)
{
super(productCatalog, loggedOnUser);
}
@Override
public void Execute() {
// TODO Add the code that will execute this command
}
}
--------------
package InventoryManagement;
import java.lang.reflect.Constructor;
/**
* Command
*/
public abstract class Command
{
//TODO: add necessary fields to this class
public Command(ProductCatalog productCatalog, User loggedOnUser)
{
}
public static Command CreateCommandDynamically(ProductCatalog productCatalog, User user, String commandClassName)
{
Class<?> concreteCommandClass = null;
Command command = null;
String packageName = "InventoryManagement";
try
{
concreteCommandClass = Class.forName(packageName + "." + commandClassName);
Constructor<?> con = concreteCommandClass.getConstructor(ProductCatalog.class, User.class);
command = (Command)con.newInstance(productCatalog, user);
}
catch (final Exception e)
{
e.printStackTrace();
}
return command;
}
//An abstract method that must be overriden in subclasses of class Command
public abstract void Execute();
}
--------------
package InventoryManagement;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* InventoryManagementSecurity
*/
public class InventoryManagementSecurity
{
public static User AuthenticateUser(String username, String password)
{
User authenticatedUser = null;
if((username.compareToIgnoreCase("admin") == 0) &&
(GetPasswordHash(password).compareToIgnoreCase("58c536ed8facc2c2a293a18a48e3e120") == 0))
{
authenticatedUser = new User(username, GetPasswordHash(password), true);
}
else
{
//TODO get the password hash using GetPasswordHash() method then try to find the user in Users.dat file
//TODO set the authenticatedUser object if successfully authenticated
}
return authenticatedUser; //Change the return value based on authentication result
}
public static boolean AddNewUser(User newUser)
{
//TODO hash password and save username and hashed password to Users.dat
return true;
}
public static boolean RemoveUser(String userName)
{
//TODO remove username from Users.dat
return true;
}
public static boolean ChangePassword(String username,
String currentPassword,
String newPassword)
{
//TODO change the password only if current password match what is on records
return true;
}
public static String GetPasswordHash(String password)
{
String generatedPassword = null;
try
{
byte[] salt = new byte[] {12, -12, 65, 61,
2, -6, -90, 12,
4, -7, -87, 2,
34, -102, 3, 115};
// Create MessageDigest instance for MD5
MessageDigest md = MessageDigest.getInstance("MD5");
// Add password bytes to digest
md.update(salt);
// Get the hash's bytes
byte[] bytes = md.digest(password.getBytes());
// This bytes[] has bytes in decimal format;
// Convert it to hexadecimal format
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bytes.length; i++) {
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
}
// Get complete hashed password in hex format
generatedPassword = sb.toString();
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
return generatedPassword;
}
}
--------------
package InventoryManagement;
/**
* Hello world!
*
*/
public class Main
{
public static void main( String[] args )
{
//THIS IS JUST AN EXAMPLE ON HOW TO AUTHENTICATE AND CREATE A COMMAND DYNAMICALLY.
//REMOVE CODE AND CHANGE AS NEEDED.
//Authenticate the user and get a user object back
User user = InventoryManagementSecurity.AuthenticateUser("admin", "admin");
ProductCatalog productCatalog = new ProductCatalog();
//TODO: You will have to read the information below from the MenuList.dat file instead of hardcoding it here.
String commandClassName = "AddProductCommand";
int optionNumber = 1;
String description = "Add Product";
Boolean isRestricted = true;
Command dynamicCommand = Command.CreateCommandDynamically(productCatalog, user, commandClassName);
System.out.println("The command concrete type is " + dynamicCommand.getClass().getSimpleName());
MenuItem menuItem = new MenuItem(dynamicCommand, optionNumber, description, isRestricted);
//Add all created MenuItems to a MenuList. Array list usage is permitted.
}
}
--------------
package InventoryManagement;
/**
* MenuItem
*/
public class MenuItem
{
public MenuItem(Command command,
int optionNumber,
String description,
Boolean isRestricted)
{
//TODO Finish the implementation of this class
System.out.println("Menu item created with command " + command.getClass().getSimpleName());
}
}
--------------
package InventoryManagement;
/**
* MenuList
*/
public class MenuList {
public MenuList(String menuHeader)
{
}
public boolean AddMenuItem(MenuItem menuItem)
{
//TODO Add menu item to the list.
return true;
}
public void StartMenu(User user)
{
//TODO Display menu items based on user type, prompt user for command, execute selected command.
}
}
--------------

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- CSC 1302: PRINCIPLES OF COMPUTER SCIENCE II Lab 6 How to Submit Please submit your answers to the lab instructor once you have completed. Failure to submit will result in a ZERO FOR THIS LAB. NO EXCEPTIONS. The class diagram with four classes Student, Graduate, Undergraduate, and Exchange is given. Write the classes as described in the class diagram. The fields and methods for each class is given below. Student Exchange Graduate Undergraduate Student: Fields: major (String) gpa (double) creditHours (int) Methods: getGpa: returns gpa getYear: returns “freshman”, “sophomore”, “junior” or “senior” as determined by earned credit hours: Freshman: Less than 32 credit hours Sophomore: At least 32 credit hours but less than 64 credit hours Junior: At least credit hours 64 but less than 96 credit hours Senior: At least 96 credit hours Graduate:…arrow_forwardBeginning tests. UNIT TEST FAILED: addInventory() Tests complete. Note: UNIT TEST FAILED is preceded by 3 spaces. 25 24 public class CallInventoryTag { public static void main(String [] args) { Scanner scnr = new Scanner (System.in); InventoryTag redSweater new InventoryTag(); int sweaterShipment; int sweaterInventoryBefore; 25 26 27 28 29 30 31 32 SweaterInventoryBefore redSweater.getQuantityRemaining() SweaterShipment = scnr.nextInt(); 33 34 System.out.println("Beginning tests."); 35 36 37 11 FIME add unit test for addInventory 38 1o Your solution goes here / 39 42 System.out.printin("Tests complete."); 42 )arrow_forwardclass implementation file -- Rectangle.cpp class Rectangle { #include #include "Rectangle.h" using namespace std; private: double width; double length; public: void setWidth (double); void setLength (double) ; double getWidth() const; double getLength() const; double getArea () const; } ; // set the width of the rectangle void Rectangle::setWidth (double w) { width = w; } // set the length of the rectangle void Rectangle::setLength (double l) { length l; //get the width of the rectangle double Rectangle::getWidth() const { return width; // more member functions herearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





