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

Hello, I need this to be done in Java using Eclypse. Thank you! public class Fil

ID: 3806267 • Letter: H

Question

Hello, I need this to be done in Java using Eclypse. Thank you!

public class FileProcessingException extends Exception

{

    private static final long serialVersionUID = 132919453665197522L;

   

    public void finalize() throws Throwable

    {

        super.finalize();

    }

    public FileProcessingException()

    {

    }

    public FileProcessingException(String message)

    {

    }

    public FileProcessingException(String message, Throwable cause)

    {

    }

}// end NotImplementedException

/**************************

import java.util.List;

import org.junit.runner.Result;

import org.junit.runner.notification.Failure;

public class TestHarness

{

    public static void main(String[] args)

    {

        trace("TestHarness");

        try

        {

            Result result = org.junit.runner.JUnitCore

                    .runClasses(Week11JUnitTest.class);

            int runs = result.getRunCount();

            int ignores = result.getIgnoreCount();

            trace(String.format("Runs: %d", runs));

            trace(String.format("Ingores: %d", ignores));

            int failCount = result.getFailureCount();

            if(failCount > 0)

            {

                List<Failure> failures = result.getFailures();

                for(Failure fail : failures)

                {

                    trace("FAILED: " + fail.getMessage());

                }

            }

            else

            {

                trace("SUCCESS");

            }

        }

        catch(Exception ex)

        {

            trace("Unhandled exception: " + ex.getMessage());

        }

    }

    private static void trace(String msg)

    {

        System.out.println(msg);

    }

}

/*************************

import static org.junit.Assert.*;

import java.io.File;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Random;

import org.junit.Test;

public class Week11JUnitTest

{

    /**

     * Pass in invalid guesses and get an InvalidArgumentException

     */

    @Test

    public void testFileProcessing()

    {

        trace("testFileProcessing");

        FileProcessor processor = new FileProcessor();

        try

        {

            String testText = generateRandomString();

            String path = processor.saveTextContent(testText);

            //String path = processor.saveTextContent2(testText);

            trace("Filepath: " + path);

            // verify the file was created

            File actualFile = new File(path);

            if( !actualFile.exists())

            {

                fail(path + " doesn't exist");

            }

            if(!verifyFile(actualFile))

            {

                fail("File didn't verify successfully");

            }

        }

        catch(FileProcessingException ex)

        {

            fail("FileProcessingException " + ex.getMessage());

        }

        catch(Exception ex)

        {

            fail("FileProcessingException " + ex.getMessage());

        }

    }

    /**

     * Verifies the list is sorted smallest to largest

     * @param list list to verify

     * @return true if sorted, otherwise false

     */

    private boolean verifyFile(File file)

    {

        boolean result = true;

        FileReader reader = null;

        try

        {

            reader = new FileReader(file);

            BufferedReader bReader = new BufferedReader(reader);

            String line = "";

            String line1 = bReader.readLine();

            String line2 = bReader.readLine();

            String line3 = bReader.readLine();

            String line4 = bReader.readLine();

            boolean first = "Week11 Test text".equals(line1.trim());

            boolean two = "Second line of the test text".equals(line2.trim());

            boolean three = "Third line 1234567890-=`~!@#$%^&*()_+qwertyuiop[]\{}|asdfghjkl;':"zxcvbnm,./<>?".equals(line3.trim());

            boolean four = line4.trim().length() > RANDOM_TEXT_SIZE;

            result = first && two && three && four;

        }

        catch(IOException ex)

        {

            result = false;

        }

        finally

        {

            if(reader != null)try{reader.close();}catch(Exception ex){}

        }

        return result;

    }

    /**

     * Generates a string of random printable characters

     * @return A random string of characters

     */

    private String generateRandomString()

    {

        StringBuilder builder = new StringBuilder(RANDOM_TEXT_SIZE);

        Random rand = new Random();

        for(int index = 0; index < RANDOM_TEXT_SIZE; index++)

        {

            int val = rand.nextInt(ASCII_TABLE_SIZE) + ASCII_PRINTABLE_OFFSET;

            builder.append((char)val);

        }

        String text = TEST_TEXT + builder.toString();

        return text;

    }

    private void trace(String msg)

    {

        System.out.println(msg);

    }

    private static int RANDOM_TEXT_SIZE = 10000; // printable characters

    private static int ASCII_TABLE_SIZE = 95; // printable characters

    private static int ASCII_PRINTABLE_OFFSET = 32;

    private static String TEST_TEXT =

"Week11 Test text "

+ "Second line of the test text "

+ "Third line 1234567890-=`~!@#$%^&*()_+qwertyuiop[]\{}|asdfghjkl;':"zxcvbnm,./<>? "

+ "Fourth line random data: "

            ;

}

create FileProcessorjava This assignment will have you save provided text to a file in the location of your choosing (needs to be agnostic to a specific system). The LestHamess will use the returned file path and verify the contents of the file you write. The JUnit test generates the text for writing and verifies against it. You can reference that for assistance Provided is FileProcessingException.java, TestHarness.java and Week11JUnitTest.java UML File Processor FILENAME Stri 1 File Prooessort) Exception saveT string) :String extContent FileProcessingException seria IVersionUID 132919453885197 22L File FrocessingException0 eProcessingException(t string) Week11 JUnitTest FileProonssingExpeption(String. Throwable) finalize0 avoid PRINTABLE OFFSET ASCI TABLE SLZE TestHarness TEST TEXT Str Test te main(Stri traoe Strin generate Randomstring0 :String testFileProcessing0 void traoe (String) :void e(File boolean

Explanation / Answer

Week11JUnitTest.java

------------------------------

package chegg;

import java.io.File;

import static org.junit.Assert.*;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Random;

import org.junit.Test;

public class Week11JUnitTest {

  

   private static int RANDOM_TEXT_SIZE = 10000; // printable characters

   private static int ASCII_TABLE_SIZE = 95; // printable characters

   private static int ASCII_PRINTABLE_OFFSET = 32;

   private static String TEST_TEXT = "Week11 Test text " + "Second line of the test text "

           + "Third line 1234567890-=`~!@#$%^&*()_+qwertyuiop[]\{}|asdfghjkl;':"zxcvbnm,./<>? "

           + "Fourth line random data: ";

  

   /**

     * Pass in invalid guesses and get an InvalidArgumentException

     */

   @Test

   public void testFileProcessing() {

       trace("testFileProcessing");

       FileProcessor processor = new FileProcessor();

       try {

           String testText = generateRandomString();

           String path = processor.saveTextContent(testText);

           trace("Filepath: " + path);

           // verify the file was created

           File actualFile = new File(path);

           if (!actualFile.exists()) {

               fail(path + " doesn't exist");

           }

           if (!verifyFile(actualFile)) {

               fail("File didn't verify successfully");

           }

       } catch (FileProcessingException ex) {

           fail("FileProcessingException " + ex.getMessage());

       } catch (Exception ex) {

           fail("FileProcessingException " + ex.getMessage());

       }

   }

   /**

     * Verifies the list is sorted smallest to largest

     *

     * @param list

     * list to verify

     * @return true if sorted, otherwise false

     */

   private boolean verifyFile(File file) {

       boolean result = true;

       FileReader reader = null;

       try {

           reader = new FileReader(file);

           BufferedReader bReader = new BufferedReader(reader);

           String line = "";

           String line1 = bReader.readLine();

           String line2 = bReader.readLine();

           String line3 = bReader.readLine();

           String line4 = bReader.readLine();

           boolean first = "Week11 Test text".equals(line1.trim());

           boolean two = "Second line of the test text".equals(line2.trim());

           boolean three = "Third line 1234567890-=`~!@#$%^&*()_+qwertyuiop[]\{}|asdfghjkl;':"zxcvbnm,./<>?"

                   .equals(line3.trim());

           boolean four = line4.trim().length() > RANDOM_TEXT_SIZE;

           result = first && two && three && four;

       } catch (IOException ex) {

           result = false;

       } finally {

           if (reader != null)

               try {

                   reader.close();

               } catch (Exception ex) {

               }

       }

       return result;

   }

   /**

     * Generates a string of random printable characters

     *

     * @return A random string of characters

     */

   private String generateRandomString() {

       StringBuilder builder = new StringBuilder(RANDOM_TEXT_SIZE);

       Random rand = new Random();

       for (int index = 0; index < RANDOM_TEXT_SIZE; index++) {

           int val = rand.nextInt(ASCII_TABLE_SIZE) + ASCII_PRINTABLE_OFFSET;

           builder.append((char) val);

       }

       String text = TEST_TEXT + builder.toString();

       return text;

   }

   private void trace(String msg) {

       System.out.println(msg);

   }

}

FileProcessingException.java

-------------------------------------

package chegg;

public class FileProcessingException extends Exception {

   private static final long serialVersionUID = 132919453665197522L;

   public FileProcessingException() {

       super();

   }

   public FileProcessingException(String message) {

       super(message);

   }

   public FileProcessingException(String message, Throwable cause) {

       super(message, cause);

   }

   public void finalize() throws Throwable {

       super.finalize();

   }

}

FileProcessor.java

------------------------

package chegg;

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

public class FileProcessor {

   public final static String FILENAME = "D:\Week11.txt";

   public FileProcessor() {

   }

   public String saveTextContent(String text) throws FileProcessingException {

       BufferedWriter bw = null;

       FileWriter fw = null;

       try {

           String content = text;

           fw = new FileWriter(FILENAME);

           bw = new BufferedWriter(fw);

           bw.write(content);

           System.out.println("Done");

       } catch (IOException e) {

           e.printStackTrace();

           throw new FileProcessingException(e.getMessage(), e.getCause());

       } finally {

           try {

               if (bw != null)

                   bw.close();

               if (fw != null)

                   fw.close();

           } catch (IOException ex) {

               ex.printStackTrace();

           }

       }

       return FILENAME;

   }

}

TestHarness.java

-----------------------

package chegg;

import java.util.List;

import org.junit.runner.Result;

import org.junit.runner.notification.Failure;

public class TestHarness {

   public static void main(String[] args) {

       trace("TestHarness");

       try {

           Result result = org.junit.runner.JUnitCore.runClasses(Week11JUnitTest.class);

           int runs = result.getRunCount();

           int ignores = result.getIgnoreCount();

           trace(String.format("Runs: %d", runs));

           trace(String.format("Ingores: %d", ignores));

           int failCount = result.getFailureCount();

           if (failCount > 0) {

               List<Failure> failures = result.getFailures();

               for (Failure fail : failures) {

                   trace("FAILED: " + fail.getMessage());

               }

           } else {

               trace("SUCCESS");

           }

       } catch (Exception ex) {

           trace("Unhandled exception: " + ex.getMessage());

       }

   }

   private static void trace(String msg) {

       System.out.println(msg);

   }

}

output

------------

TestHarness

testFileProcessing

Done

Filepath: D:Week11.txt

Runs: 1

Ingores: 0

SUCCESS

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