Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need this to be done in Java using Eclypse. Thank you! public class FileProcessingException extends Exception { private static final long serialVersionUID =

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

image text in transcribed

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 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: "

;

}

image text in transcribed

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

What are your Flight Time Limitations

Answered: 1 week ago