java testing work
This commit is contained in:
		
							parent
							
								
									8b17941edb
								
							
						
					
					
						commit
						bc29b044dc
					
				| @ -0,0 +1,11 @@ | ||||
| package org.baeldung.java.io; | ||||
| 
 | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| 
 | ||||
| public class JavaXToByteArrayUnitTest { | ||||
|     protected final Logger logger = LoggerFactory.getLogger(getClass()); | ||||
| 
 | ||||
|     // tests - X to Byte Array | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,53 @@ | ||||
| package org.baeldung.java.io; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| import java.io.StringWriter; | ||||
| import java.io.Writer; | ||||
| 
 | ||||
| import org.apache.commons.io.output.StringBuilderWriter; | ||||
| import org.junit.Test; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| 
 | ||||
| import com.google.common.io.CharSink; | ||||
| 
 | ||||
| public class JavaXToWriterUnitTest { | ||||
|     protected final Logger logger = LoggerFactory.getLogger(getClass()); | ||||
| 
 | ||||
|     // tests - byte[] to Writer | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenPlainJava_whenConvertingByteArrayIntoWriter_thenCorrect() throws IOException { | ||||
|         final byte[] initialArray = "With Java".getBytes(); | ||||
| 
 | ||||
|         final Writer targetWriter = new StringWriter().append(new String(initialArray)); | ||||
| 
 | ||||
|         targetWriter.close(); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenUsingGuava_whenConvertingByteArrayIntoWriter_thenCorrect() throws IOException { | ||||
|         final byte[] initialArray = "With Guava".getBytes(); | ||||
| 
 | ||||
|         final String buffer = new String(initialArray); | ||||
|         final StringWriter stringWriter = new StringWriter(); | ||||
|         final CharSink charSink = new CharSink() { | ||||
|             @Override | ||||
|             public final Writer openStream() throws IOException { | ||||
|                 return stringWriter; | ||||
|             } | ||||
|         }; | ||||
|         charSink.write(buffer); | ||||
| 
 | ||||
|         stringWriter.close(); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void givenUsingCommonsIO_whenConvertingByteArrayIntoWriter_thenCorrect() throws IOException { | ||||
|         final byte[] initialArray = "With Commons IO".getBytes(); | ||||
|         final Writer targetWriter = new StringBuilderWriter(new StringBuilder(new String(initialArray))); | ||||
| 
 | ||||
|         targetWriter.close(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user