Andrei Branza - removed old code from old module

This commit is contained in:
Andrei Branza 2024-04-11 17:04:01 +03:00
parent 9b0e10496a
commit 3826c5b8e6
1 changed files with 0 additions and 113 deletions

View File

@ -1,113 +0,0 @@
package com.baeldung.printwriterwritevsprint;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
public class WriteVsPrintUnitTest {
Object outputFromPrintWriter;
Object outputFromPrintWriter() {
try (BufferedReader br = new BufferedReader(new FileReader("output.txt"))){
outputFromPrintWriter = br.readLine();
} catch (IOException e){
e.printStackTrace();
Assertions.fail();
}
return outputFromPrintWriter;
}
@Test
void whenUsingWriteInt_thenASCIICharacterIsPrinted() throws FileNotFoundException {
PrintWriter printWriter = new PrintWriter("output.txt");
printWriter.write(48);
printWriter.close();
assertEquals("0", outputFromPrintWriter());
}
@Test
void whenUsingWriteCharArrayFromOffset_thenCharArrayIsPrinted() throws FileNotFoundException {
PrintWriter printWriter = new PrintWriter("output.txt");
printWriter.write(new char[]{'A','/','&','4','E'}, 1, 4 );
printWriter.close();
assertEquals("/&4E", outputFromPrintWriter());
}
@Test
void whenUsingWriteStringFromOffset_thenLengthOfStringIsPrinted() throws FileNotFoundException {
PrintWriter printWriter = new PrintWriter("output.txt");
printWriter.write("StringExample", 6, 7 );
printWriter.close();
assertEquals("Example", outputFromPrintWriter());
}
@Test
void whenUsingPrintBoolean_thenStringValueIsPrinted() throws FileNotFoundException {
PrintWriter printWriter = new PrintWriter("output.txt");
printWriter.print(true);
printWriter.close();
assertEquals("true", outputFromPrintWriter());
}
@Test
void whenUsingPrintChar_thenCharIsPrinted() throws FileNotFoundException {
PrintWriter printWriter = new PrintWriter("output.txt");
printWriter.print('A');
printWriter.close();
assertEquals("A", outputFromPrintWriter());
}
@Test
void whenUsingPrintInt_thenValueOfIntIsPrinted() throws FileNotFoundException {
PrintWriter printWriter = new PrintWriter("output.txt");
printWriter.print(420);
printWriter.close();
assertEquals("420", outputFromPrintWriter());
}
@Test
void whenUsingPrintString_thenStringIsPrinted() throws FileNotFoundException {
PrintWriter printWriter = new PrintWriter("output.txt");
printWriter.print("RandomString");
printWriter.close();
assertEquals("RandomString", outputFromPrintWriter());
}
@Test
void whenUsingPrintObject_thenObjectToStringIsPrinted() throws FileNotFoundException {
PrintWriter printWriter = new PrintWriter("output.txt");
Map example = new HashMap();
printWriter.print(example);
printWriter.close();
assertEquals(example.toString(), outputFromPrintWriter());
}
}