Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java programming: The following 6 questions refers to the following code import

ID: 3909101 • Letter: J

Question

Java programming:

The following 6 questions refers to the following code import static org.junit.Assert.*; public class BookCollectionTest BookCollection coll; public class BookCollection{ BeforeClass public static void doBeforeClass ) ArrayList myColl; public BookCollection ) myColl -new ArrayList ; Before public void doBefore) public void add (Book b) myColl.add (b) Test public void testAdd ) public void remove (Book b)f myColl.remove (b); public boolean contains (Book b) Test return myColl.contains (b) public void testRemove ) 1) 45. When running this JUnit class, A. doBeforeClass is executed once before all tests B. doBeforeClass is run once before each test, C. it is not possible to tell when doBeforeClass is run, D. doBeforeClass can be called on in any order, E. doBeforeClass cannot be static 1) 46. When running this JUnit class, A. doBefore is executed once before all tests, B. doBefore is run once before each test, C. it is not possible to tell when doBefore is run, D. doBefore can be called on in any order, E. doBefore must be static.

Explanation / Answer

To answer the question, we need to understand that

@BeforeClass method is run only once before @Before and all tests

@Before method is run before each test

============

Answer 45) option A) doBeforeClass is executed once before all tests

-------

Answer 46) option B) doBefore is run once before each test

---------

Answer 47) none of the above

The correct statement should be

coll = new BookCollection();

The variable name in the answer options is myColl where as the one inside the Junit test is coll. The names don't match

----------

Answer 48) option A) coll = new BookCollection();

-----------

Answer 49) option A) assertTrue(coll.contains(b));

------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote