我在我的一个测试中有以下代码:
List<Long> wordList = wordService.listAll().stream()
.map(StudiedWord::getId)
.collect(Collectors.toList());
StudiedWord是龙目岛的POJO:
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class StudiedWord extends AbstractModelClass {
private String text;
private String translation;
private WordStage stage;
private String image;
private String sound;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
abstract class AbstractModelClass implements ModelObject {
@Id
@GeneratedValue
private Long id;
}
我可以从IntelliJ IDEA运行测试,一切正常。我可以使用Gradle从终端手动运行测试,并且一切正常。
但是在特拉维斯,我经常遇到以下错误:
WordSetControllerTest > deleteWordSet FAILED
java.lang.IllegalAccessError at WordSetControllerTest.java:255
第255行是map语句和方法引用的行。如果我用lambda表达式(studiedWord -> studiedWord.getId()
)替换方法引用,那么一切都很好。
以下是我的.travis.yml的内容:
language: java
jdk:
- oraclejdk8
以下是我的测试结构示例:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
@Slf4j
public abstract class MockMvcBase {
/// common fields and methods for mock mvc tests
}
@Transactional
public class WordSetControllerTest extends MockMvcBase {
@Autowired
private WordService wordService;
@Autowired
private WordSetService wordSetService;
// other methods
@Test
public void deleteWordSetById() throws Exception {
// test logic
List<Long> wordList = wordService.listAll().stream()
.map(StudiedWord::getId)
.collect(Collectors.toList());
// assertions
}
}
我还有其他测试,我在其他Lombok生成的方法中使用方法引用,它们工作正常。
我的Travis配置有问题或者我错过了什么?