Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need to implement this code using Java but somehow I am getting confused on how to implement it correctly and do the testing using
I need to implement this code using Java but somehow I am getting confused on how to implement it correctly and do the testing using JUnit. Any help will be highly appreciated. Thank you.
- Can eliminate the duplication (and potential laborious and error-prone maintenance work) by - moving those common data fields and their getter/setter methods to a super class of Directory and File. \begin{tabular}{|l|} \hline \multicolumn{2}{|c|}{ FileSystem } \\ \hline \end{tabular} - How to design directory-todirectory structures? - How to design file-to-directory structures? - No problem to use class inheritance here - A directory is never transformed to be a file, and vice versa. Composite Design Pattern 23 2 Benefits of Composite - Client code of a tree structure can treat individual objects and compositions of objects uniformly. - Objects files - Compositions of objects directories - "Treating...uniformly" means... - Having common data fields and methods among ... in a super class, and - Performing polymorphism on .... Directory dix =; for ( FSElement fsElement: dix.getChildren () ) t fazlement.getName () ; fsElement.gatsize(); fszlement.getParent () . getName (); ) \begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{>} \\ FileSvstem \\ \hline -FileSystem() \\ +getFileSystem(): FileSystem \\ +getRootDirs(): LinkedListHW, in which you did equality-check for different Car instances - Filetest - Implement an equality-check for each File instance by calling getter methods of File - Use name, size and parent for equality check. Test Fixtures * publio DirectoryTest - Fixture private String dixToStringAxray(Directory d) [ - An instance of a class under - Set up of a file(s) and other String[l dirInfo = l test resources d. getame (), d.getsize (), d. getPaxent () - getName ()); - An instance of another class - e.g.. Socket return dixInfo; 1 that the class under test - Set up of external depends on systems/frameworks - Input data - e.g. Database, web server, web - Expected result(s) app framework, emulator (e.g. String[] expeeted ={,} Android emulator) Directory actual =; assertAxrayEquals (expected, dirTostringhrray (actual) ; ; 1 QTest publia void verifyDirectoryEqualityhome () 11 3 Setting up Fixtures Implicit Setup publie elass CaleulatorTast f private atatj \&Beforedli public static void setug() ! cut = new Calculator(); ) grest publie void multiply 38y 4() f float actual = cut. multiply (3,4); float expected = 12; float expected =12; assertaquals (expected, actual): Prest public void divide 3By 201 () float actual = cut, dividion float actual = cut, divide (3,2); Prest puble void divide5zyo() ... exfterkl1 public static void dosomething() () 1 Preparing a Fixture for Multiple Test Classes - Implicit setup makes a test class less redundant. - Define a separate class that is responsible for creating - Flow of execution a fixture(s). - @BeforeAll setUp() - @Test multiply3By4() - @Test divide3By2() \begin{tabular}{|c|} \hline TestFixturelnitializer \\ \hline+ createFS(...): FileSystem \\ \hline ( \\ \hline \end{tabular} - @Test divide5By0() Create a file system structure - @AfterAll doSomething() - The @BeforeAll method runs before all test methods. - The@AfterAll method runs after all test methods. - JUnit may run the test methods in a different order from their ordering in source code. Nntac: Just in Case: Major Collection Types in Java - List - Orders elements with integer index numbers. - Offers index-based random access. - Can contain duplicate elements. - Queue - Orders elements with links. - Offers FIFO (First-In-First-Out) access. - Can contain duplicate elements. - Dequeue - Stands for "Double Ended QUEUE" (pronounced "deck"). - Orders elements with links. - Offers both FIFO and LIFO (Last-In-First-Out) access. - Can contain duplicate elements. - Set - Contains non-duplicate elements without an order. - Map - Contains key-value pairs (wi non-duplicate keys) without an order. ArrayList v.s. LinkedList - ArrayList - LinkedList - Array-based - Link-based implementation of the List implementation of the List interface and Deque interfaces - Can eliminate the duplication (and potential laborious and error-prone maintenance work) by - moving those common data fields and their getter/setter methods to a super class of Directory and File. \begin{tabular}{|l|} \hline \multicolumn{2}{|c|}{ FileSystem } \\ \hline \end{tabular} - How to design directory-todirectory structures? - How to design file-to-directory structures? - No problem to use class inheritance here - A directory is never transformed to be a file, and vice versa. Composite Design Pattern 23 2 Benefits of Composite - Client code of a tree structure can treat individual objects and compositions of objects uniformly. - Objects files - Compositions of objects directories - "Treating...uniformly" means... - Having common data fields and methods among ... in a super class, and - Performing polymorphism on .... Directory dix =; for ( FSElement fsElement: dix.getChildren () ) t fazlement.getName () ; fsElement.gatsize(); fszlement.getParent () . getName (); ) \begin{tabular}{|l|} \hline \multicolumn{1}{|c|}{>} \\ FileSvstem \\ \hline -FileSystem() \\ +getFileSystem(): FileSystem \\ +getRootDirs(): LinkedListHW, in which you did equality-check for different Car instances - Filetest - Implement an equality-check for each File instance by calling getter methods of File - Use name, size and parent for equality check. Test Fixtures * publio DirectoryTest - Fixture private String dixToStringAxray(Directory d) [ - An instance of a class under - Set up of a file(s) and other String[l dirInfo = l test resources d. getame (), d.getsize (), d. getPaxent () - getName ()); - An instance of another class - e.g.. Socket return dixInfo; 1 that the class under test - Set up of external depends on systems/frameworks - Input data - e.g. Database, web server, web - Expected result(s) app framework, emulator (e.g. String[] expeeted ={,} Android emulator) Directory actual =; assertAxrayEquals (expected, dirTostringhrray (actual) ; ; 1 QTest publia void verifyDirectoryEqualityhome () 11 3 Setting up Fixtures Implicit Setup publie elass CaleulatorTast f private atatj \&Beforedli public static void setug() ! cut = new Calculator(); ) grest publie void multiply 38y 4() f float actual = cut. multiply (3,4); float expected = 12; float expected =12; assertaquals (expected, actual): Prest public void divide 3By 201 () float actual = cut, dividion float actual = cut, divide (3,2); Prest puble void divide5zyo() ... exfterkl1 public static void dosomething() () 1 Preparing a Fixture for Multiple Test Classes - Implicit setup makes a test class less redundant. - Define a separate class that is responsible for creating - Flow of execution a fixture(s). - @BeforeAll setUp() - @Test multiply3By4() - @Test divide3By2() \begin{tabular}{|c|} \hline TestFixturelnitializer \\ \hline+ createFS(...): FileSystem \\ \hline ( \\ \hline \end{tabular} - @Test divide5By0() Create a file system structure - @AfterAll doSomething() - The @BeforeAll method runs before all test methods. - The@AfterAll method runs after all test methods. - JUnit may run the test methods in a different order from their ordering in source code. Nntac: Just in Case: Major Collection Types in Java - List - Orders elements with integer index numbers. - Offers index-based random access. - Can contain duplicate elements. - Queue - Orders elements with links. - Offers FIFO (First-In-First-Out) access. - Can contain duplicate elements. - Dequeue - Stands for "Double Ended QUEUE" (pronounced "deck"). - Orders elements with links. - Offers both FIFO and LIFO (Last-In-First-Out) access. - Can contain duplicate elements. - Set - Contains non-duplicate elements without an order. - Map - Contains key-value pairs (wi non-duplicate keys) without an order. ArrayList v.s. LinkedList - ArrayList - LinkedList - Array-based - Link-based implementation of the List implementation of the List interface and Deque interfacesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started