Question: Need to write JUnit test class for the code below: ************************************************************************ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class

Need to write JUnit test class for the code below:

************************************************************************

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

public class BiblioFileIO {

public static final int READER = 0;

public static final int WRITER = 1;

private BufferedReader reader;

private BufferedWriter writer;

private File file;

public BiblioFileIO() {

file = new File( "bibliography.txt" );

}

public BiblioFileIO( String fileName ) {

file = new File( fileName );

}

public void close( int which ) {

try {

switch ( which ) {

case READER:

if ( reader != null ) {

reader.close();

}

break;

case WRITER:

if ( writer != null ) {

writer.close();

}

break;

}

} catch ( IOException e ) {

System.out.print( e.getMessage() );

}

}

public boolean open( int which ) {

boolean success = false;

try {

if ( which == READER ) {

if ( file.exists() && file.canRead() ) {

reader = new BufferedReader( new FileReader( file ) );

success = true;

}

} else if ( which == WRITER ) {

writer = new BufferedWriter( new FileWriter( file ) );

success = true;

}

} catch ( IOException e ) {

success = false;

}

return success;

}

public String readLine() {

String line;

try {

line = reader.readLine();

} catch ( IOException | NullPointerException e ) {

line = null;

}

return line;

}

public void write( String line ) {

try {

if ( writer != null ) {

writer.write( line );

writer.newLine();

}

} catch ( IOException e ) {

System.out.print( e.getMessage() );

}

}

public void deleteFile() {

file.delete();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!