<commit_before>package test.learning.java.io;

import static org.junit.Assert.*;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.Test;

public class _6_BufferedOutputStreamTest {

	@Test
	public void bufferedStreamAutoflushesItsContentWhenTheBufferIsFull() throws IOException {
		int bufferSize = 2;
		ByteArrayOutputStream outputStore = new ByteArrayOutputStream();
		BufferedOutputStream outputStream = new BufferedOutputStream(outputStore, bufferSize);
		
		outputStream.write((byte) 1);
		assertEquals(0, outputStore.toByteArray().length);
		
		outputStream.write((byte) 2);
		assertEquals(0, outputStore.toByteArray().length);
		
		outputStream.write((byte) 3);
		assertEquals("exceeding the buffer length should write the buffered bytes to the underlying output stream", 2, outputStore.toByteArray().length);
		
		outputStream.close();
	}
	
	@Test
	public void flushCommitsTheBufferedBytesInToTheSink() throws IOException {
		int bufferSize = 2;
		ByteArrayOutputStream outputStore = new ByteArrayOutputStream();
		BufferedOutputStream outputStream = new BufferedOutputStream(outputStore, bufferSize);
		
		outputStream.write((byte) 1);
		assertEquals(0, outputStore.toByteArray().length);
		
		outputStream.write((byte) 2);
		assertEquals(0, outputStore.toByteArray().length);
		
		outputStream.flush();
		assertEquals("flush should write the buffered bytes to the underlying output stream", 2, outputStore.toByteArray().length);
		
		outputStream.close();
	}

}<commit_msg>Refactoring.<commit_after>package test.learning.java.io;

import static org.junit.Assert.*;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.Test;

public class _6_BufferedOutputStreamTest {

	@Test
	public void bufferedStreamAutoflushesItsContentWhenTheBufferIsFull() throws IOException {
		int bufferSize = 2;
		ByteArrayOutputStream outputStore = new ByteArrayOutputStream();
		BufferedOutputStream bufferedOoutput = new BufferedOutputStream(outputStore, bufferSize);
		
		bufferedOoutput.write((byte) 1);
		assertEquals(0, outputStore.toByteArray().length);
		
		bufferedOoutput.write((byte) 2);
		assertEquals(0, outputStore.toByteArray().length);
		
		bufferedOoutput.write((byte) 3);
		assertEquals("should auto-flush the content", 2, outputStore.toByteArray().length);
		
		bufferedOoutput.close();
	}
	
	@Test
	public void flushCommitsTheBufferedBytesInToTheSink() throws IOException {
		int bufferSize = 2;
		ByteArrayOutputStream outputStore = new ByteArrayOutputStream();
		BufferedOutputStream bufferedOoutput = new BufferedOutputStream(outputStore, bufferSize);
		
		bufferedOoutput.write((byte) 1);
		assertEquals(0, outputStore.toByteArray().length);
		
		bufferedOoutput.write((byte) 2);
		assertEquals(0, outputStore.toByteArray().length);
		
		bufferedOoutput.flush();
		assertEquals("should commit the buffer", 2, outputStore.toByteArray().length);
		
		bufferedOoutput.close();
	}

}
{'fraction_non_alphanumeric': 0.10224274406332454, 'fraction_numerical': 0.009234828496042216, 'mean_word_length': 5.956422018348624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '259232', 'n_tokens_mistral': 942, 'n_tokens_neox': 811, 'n_words': 187}