我编写了一个枚举类型,当我运行为其创建的 JUnit 测试时,该类型会出现以下语法错误:
java.lang.Error: Unresolved compilation problems:
Syntax error, insert "enum Identifier" to complete EnumHeaderName
Syntax error, insert "EnumBody" to complete EnumDeclaration
Syntax error, insert "}" to complete ClassBody
我的枚举类型具有静态函数,对于特定的字符串,返回一个枚举常量。这是我的一些枚举类型的代码:
public enum MusicType {
ACCIDENTAL, LETTER, OCTAVE, REST, DUR, CHORD, TUPLET;
public static MusicType is_accidental(String a){
if (a=="^" | a=="_"|a=="=")
return ACCIDENTAL;
else return null;
}
}
我的其余静态函数非常相似(即is_letter
, is_octave
等),尽管有些使用input.matches(regex)
函数而不是检查输入是否等于特定字符串。
这是 JUnit 测试的开始,它测试处理意外常量的函数:
public class MusicTypeTest {
@Test
public void accidentalTest(){
String sharp = "^";
String flat = "_";
String natural = "=";
assertEquals(MusicType.ACCIDENTAL, MusicType.is_accidental(sharp));
assertEquals(MusicType.ACCIDENTAL, MusicType.is_accidental(flat));
assertEquals(MusicType.ACCIDENTAL, MusicType.is_accidental(natural));
}
}
我的 JUnit 测试中测试所有枚举静态函数的其他函数的编码类似。我无法弄清楚为什么会出现这些语法错误(这是我第一次编码枚举类型)。我一直在 Eclipse 中编码,到目前为止还没有发现任何丢失的“}”。我不知道这是否与我编写测试的方式或声明变量的方式有关。有谁知道为什么我有这些语法错误?