Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Blatt18;
- import java.io.*;
- import org.junit.Test;
- import static org.junit.Assert.*;
- public class ToUpperCaseWriterTest {
- public void test(char c, char result) {
- try(ByteArrayOutputStream baos = new ByteArrayOutputStream();
- OutputStreamWriter osw = new OutputStreamWriter(baos);
- ToUpperCaseWriter writer = new ToUpperCaseWriter(osw);) {
- writer.write(c);
- writer.flush();
- String upperCase = baos.toString();
- assertEquals(result, upperCase);
- }
- catch(IOException e){
- fail("IOException" + e.getMessage());
- }
- }
- @Test
- public void writeCharTest() {
- test('a', 'A');
- }
- @Test
- public void writeCharTestWithNoChar() {
- test('1', '1');
- }
- @Test
- public void asciiCode() {
- char[] ca = new char[128];
- for(int i = 0; i < ca.length; i++){
- ca[i] = (char) i;
- }
- for(int i = 0; i < ca.length; i++) {
- if(i < 97 || i > 122) {
- test(ca[i], ca[i]);
- }
- else{
- char temp = Character.toUpperCase(ca[i]);
- test(ca[i], temp);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement