Просмотр исходного кода

Merge pull request #731 from McEileen/rna-transcription-invalid-input

Add tests to catch invalid input edge cases
Logan Stucki 9 лет назад
Родитель
Сommit
ef184d585b

+ 3
- 0
exercises/rna-transcription/src/example/java/RnaTranscription.java Просмотреть файл

@@ -16,6 +16,9 @@ public class RnaTranscription {
16 16
                 case 'T':
17 17
                     sb.append('A');
18 18
                     break;
19
+                default:
20
+                    throw new IllegalArgumentException("Invalid input");
21
+
19 22
             }
20 23
         }
21 24
         return sb.toString();

+ 33
- 0
exercises/rna-transcription/src/test/java/RnaTranscriptionTest.java Просмотреть файл

@@ -2,9 +2,18 @@ import org.junit.Assert;
2 2
 import org.junit.Before;
3 3
 import org.junit.Ignore;
4 4
 import org.junit.Test;
5
+import org.junit.rules.ExpectedException;
6
+import org.junit.Rule;
5 7
 
6 8
 public class RnaTranscriptionTest {
7 9
 
10
+    /*
11
+    version: 2.0.0
12
+     */
13
+
14
+    @Rule
15
+    public ExpectedException thrown = ExpectedException.none();
16
+
8 17
     private RnaTranscription rnaTranscription;
9 18
 
10 19
     @Before
@@ -46,4 +55,28 @@ public class RnaTranscriptionTest {
46 55
     public void testRnaTranscription() {
47 56
         Assert.assertEquals("UGCACCAGAAUU", rnaTranscription.transcribe("ACGTGGTCTTAA"));
48 57
     }
58
+
59
+    @Ignore("Remove to run test")
60
+    @Test
61
+    public void testRnaTranscriptionOfRnaThrowsAnError() {
62
+        thrown.expect(IllegalArgumentException.class);
63
+        thrown.expectMessage("Invalid input");
64
+        rnaTranscription.transcribe("U");
65
+    }
66
+
67
+    @Ignore("Remove to run test")
68
+    @Test
69
+    public void testRnaTranscriptionOfInvalidInputThrowsAnError() {
70
+        thrown.expect(IllegalArgumentException.class);
71
+        thrown.expectMessage("Invalid input");
72
+        rnaTranscription.transcribe("BFV");
73
+    }
74
+
75
+    @Ignore("Remove to run test")
76
+    @Test
77
+    public void testRnaTranscriptionOfPartiallyInvalidInput() {
78
+        thrown.expect(IllegalArgumentException.class);
79
+        thrown.expectMessage("Invalid input");
80
+        rnaTranscription.transcribe("GCVV");
81
+    }
49 82
 }