Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. package Blatt18;
  2.  
  3. import java.io.*;
  4.  
  5. import org.junit.Test;
  6.  
  7. import static org.junit.Assert.*;
  8.  
  9. public class ToUpperCaseWriterTest {
  10.  
  11. public void test(char c, char result) {
  12.  
  13. try(ByteArrayOutputStream baos = new ByteArrayOutputStream();
  14. OutputStreamWriter osw = new OutputStreamWriter(baos);
  15. ToUpperCaseWriter writer = new ToUpperCaseWriter(osw);) {
  16.  
  17.  
  18.  
  19. writer.write(c);
  20. writer.flush();
  21. String upperCase = baos.toString();
  22. assertEquals(result, upperCase);
  23. }
  24. catch(IOException e){
  25. fail("IOException" + e.getMessage());
  26. }
  27. }
  28. @Test
  29. public void writeCharTest() {
  30. test('a', 'A');
  31. }
  32. @Test
  33. public void writeCharTestWithNoChar() {
  34. test('1', '1');
  35. }
  36. @Test
  37. public void asciiCode() {
  38. char[] ca = new char[128];
  39. for(int i = 0; i < ca.length; i++){
  40. ca[i] = (char) i;
  41. }
  42. for(int i = 0; i < ca.length; i++) {
  43. if(i < 97 || i > 122) {
  44. test(ca[i], ca[i]);
  45. }
  46. else{
  47. char temp = Character.toUpperCase(ca[i]);
  48. test(ca[i], temp);
  49. }
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement