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

Create a JUNIT test program in Java for this program: *This is the template to f

ID: 3794355 • Letter: C

Question

Create a JUNIT test program in Java for this program:

*This is the template to fill in for the solution - please fill in these functions to complete the JUNIT Test Class*

/**
*
*/
package edu.odu.cs.cs350;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* @author Colten Everitt
*
*/
public class DurationClassTest {

   /**
   * @throws java.lang.Exception
   */
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @AfterClass
   public static void tearDownAfterClass() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @Before
   public void setUp() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @After
   public void tearDown() throws Exception {
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#hashCode()}.
   */
   @Test
   public final void testHashCode() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration()}.
   */
   @Test
   public final void testDuration() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration(long)}.
   */
   @Test
   public final void testDurationLong() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration(int, int, int, int)}.
   */
   @Test
   public final void testDurationIntIntIntInt() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getTotalSeconds()}.
   */
   @Test
   public final void testGetTotalSeconds() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#setTotalSeconds(long)}.
   */
   @Test
   public final void testSetTotalSeconds() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getDays()}.
   */
   @Test
   public final void testGetDays() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getHours()}.
   */
   @Test
   public final void testGetHours() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getMinutes()}.
   */
   @Test
   public final void testGetMinutes() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getSeconds()}.
   */
   @Test
   public final void testGetSeconds() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#add(edu.odu.cs.cs350.Duration)}.
   */
   @Test
   public final void testAdd() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#subtract(edu.odu.cs.cs350.Duration)}.
   */
   @Test
   public final void testSubtract() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#scale(double)}.
   */
   @Test
   public final void testScale() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#toString()}.
   */
   @Test
   public final void testToString() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#equals(java.lang.Object)}.
   */
   @Test
   public final void testEqualsObject() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#clone()}.
   */
   @Test
   public final void testClone() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#Object()}.
   */
   @Test
   public final void testObject() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#getClass()}.
   */
   @Test
   public final void testGetClass() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#equals(java.lang.Object)}.
   */
   @Test
   public final void testEqualsObject1() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#clone()}.
   */
   @Test
   public final void testClone1() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#toString()}.
   */
   @Test
   public final void testToString1() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#notify()}.
   */
   @Test
   public final void testNotify() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#notifyAll()}.
   */
   @Test
   public final void testNotifyAll() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#wait(long)}.
   */
   @Test
   public final void testWaitLong() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#wait(long, int)}.
   */
   @Test
   public final void testWaitLongInt() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#wait()}.
   */
   @Test
   public final void testWait() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link java.lang.Object#finalize()}.
   */
   @Test
   public final void testFinalize() {
       fail("Not yet implemented"); // TODO
   }

}

Explanation / Answer

package edu.odu.cs.cs350;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public static void main(String[] args) {
//ArrayList of type String
ArrayList data = new ArrayList();
try{
Scanner s = new Scanner(new FileInputStream("C:/Documents/assn2data.txt"));
String line;
int sum=0;
// Read Each line of File Using hasNextLine()
while(s.hasNextLine()){
line = s.nextLine(); // nextLine() is to retrieve
sum = sum+line.length();
data.add(line); //Adding line to ArrayList
}
  
System.out.println("The number of Entries are:"+data.size());
System.out.println("The number of characters:"+sum);
  

/**
* @author Colten Everitt
*
*/
public class DurationClassTest {

   /**
   * @throws java.lang.Exception
   */
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @AfterClass
   public static void tearDownAfterClass() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @Before
   public void setUp() throws Exception {
   }

   /**
   * @throws java.lang.Exception
   */
   @After
   public void tearDown() throws Exception {
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#hashCode()}.
   */
   @Test
   public final void testHashCode() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration()}.
   */
   @Test
   public final void testDuration() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration(long)}.
   */
   @Test
   public final void testDurationLong() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#Duration(int, int, int, int)}.
   */
   @Test
   public final void testDurationIntIntIntInt() {
       fail("Not yet implemented"); // TODO
   }

   /**
   * Test method for {@link edu.odu.cs.cs350.Duration#getTotalSeconds()}.
   */
   @Test
   public final void testGetTotalSeconds() {
       fail("Not yet implemented"); // TODO
   }

}

  
data.add(0, "*****The file has been modified on*****");
data.add(data.size(), "*****Number of lines remaining are******");
  
System.out.println("Storing Data into file after being modified..");
  
int j=0;
  
//Writing modified data into file
PrintWriter p = new PrintWriter("C:/Users/Documents/assn2data-modified.txt");
BufferedWriter b = new BufferedWriter(p);
while(data.size()>j){
b.write(data.get(j));
b.newLine();
j++;
}
b.close();
p.close();
  
System.out.println("Data is stored into modified file..");
}   

}