Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 8e00a4b

Browse files
committed
A bit of proactive defense
There are times when the first four lines of a unit test for a Java program are missing, causing the tests to fail. I do not know where, when, or why this is happening. But this checks to see if the important things are missing right before they are sent to JOBE. If they are missing I add them.
1 parent 9be16a4 commit 8e00a4b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

runestone/activecode/js/activecode.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export class ActiveCode extends RunestoneBase {
121121
}
122122
suffStart = this.code.indexOf("====");
123123
if (suffStart > -1) {
124+
// The +5 gets past the ====\n
124125
this.suffix = this.code.substring(suffStart + 5);
125126
this.code = this.code.substring(0, suffStart);
126127
}

runestone/activecode/js/livecode.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ export default class LiveCode extends ActiveCode {
101101

102102
// extract the class names so files can be named properly
103103
if (this.suffix && this.language == "java") {
104+
// the suffix contains unit test code and should include and import of junit
105+
// import static org.junit.Assert.*;
106+
// import org.junit.*;
107+
// import java.io.*;
108+
if (this.suffix.indexOf("import org.junit") <0 ) {
109+
console.log(`Missing imports in unit tests:
110+
${this.suffix}`);
111+
// alert("The unit tests for this problem are incomplete, Please report this.");
112+
this.suffix = `
113+
import static org.junit.Assert.*;
114+
import org.junit.*;
115+
import java.io.*;
116+
` + this.suffix;
117+
}
104118
let classMatch = new RegExp(/public class\s+(\w+)[\s+{]/);
105119
source = await this.buildProg(false);
106120
let m = source.match(classMatch);

0 commit comments

Comments
 (0)