Question: org.opentest 4 j . AssertionFailedError: Something went wrong! best i can tell is null at org.junit.jupiter.api.AssertionUtils.fail ( AssertionUtils . java: 3 9 ) at org.junit.jupiter.api.Assertions.fail

org.opentest4j.AssertionFailedError: Something went wrong! best i can tell is null
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:39)
at org.junit.jupiter.api.Assertions.fail(Assertions.java:109)
at MachineTests.testMachineCreationArray(MachineTests.java:326) org.opentest4j.AssertionFailedError: Something went wrong! best i can tell is null
at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:39)
at org.junit.jupiter.api.Assertions.fail(Assertions.java:109)
at MachineTests.testMachineTurnValid(MachineTests.java:469) How to fix these issues here is my code import java.util.List;
import java.util.ArrayList;
public class Machine {
private int[] ans;
private List verifierss;
public Machine(int[] ans, Verifier[] verifierss) throws IncorrectDataException {
correctAns(ans);
this.ans = ans;
this.verifierss = List.of(verifierss);
}
public Machine(int[] ans, List verifierss) throws IncorrectDataException {
correctAns(ans);
this.ans = ans;
this.verifierss = new ArrayList<>(verifierss);
}
private void correctAns(int[] ans) throws IncorrectDataException {
if (ans.length !=3){
throw new IncorrectDataException("Answer must consist of exactly 3 digits.");
}
for (int n : ans){
if (n <1|| n >5){
throw new IncorrectDataException("Digits must be within the range 1-5.");
}
}
}
public String toString(){
StringBuilder stringbuilder = new StringBuilder("Verifiers:
");
char verifierCh ='A';
for (Verifier verifier : verifierss){
stringbuilder.append(verifierCh).append(")").append(verifier.toString()).append("
");
verifierCh++;
}
return stringbuilder.toString().trim();
}
public String turn(int[] guess, char[] verifierChoice) throws IncorrectDataException {
correctGuess(guess);
if (verifierChoice.length !=3){
throw new IncorrectDataException("There must be exactly 3 selected verifiers.");
}
StringBuilder stringbuilder = new StringBuilder("Results for guess ");
for (int n : guess){
stringbuilder.append(n);
}
stringbuilder.append(":
");
List sortedChoice = new ArrayList<>();
for (char c : verifierChoice){
sortedChoice.add(Character.toUpperCase(c));
}
sortedChoice.sort(Character::compareTo);
for (char choicee : sortedChoice){
int i = choicee -'A';
if (i <0|| i >= verifierss.size()){
throw new IncorrectDataException("Selected verifier is out of bounds.");
}
Verifier verifier = verifierss.get(i);
stringbuilder.append(choicee).append(")").append(verifier.check(guess, ans)).append("
");
}
return stringbuilder.toString().trim();
}
public String turn(int[] guess, String verifierChoice) throws IncorrectDataException {
char[] choiceArray = verifierChoice.replace("","").toCharArray();
return turn(guess, choiceArray);
}
public boolean finalGuess(int[] guess) throws IncorrectDataException {
correctGuess(guess);
for (int i =0; i < guess.length; i++){
if (guess[i]!= ans[i]){
return false;
}
}
return true;
}
private void correctGuess(int[] guess) throws IncorrectDataException {
if (guess.length !=3){
throw new IncorrectDataException("Guess must consist of exactly 3 digits.");
}
for (int n : guess){
if (n <1|| n >5){
throw new IncorrectDataException("Digits must be within the range 1-5.");
}
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!