我在Lombok和JUnit方面遇到了问题。
我使用最新版本的IntelliJ Idea,并安装了Lombok插件并启用了注解处理功能。
我有一个实体类:
@Data
@Builder
@AllArgsConstructor
public class User {
private String name;
private String email;
}
build.gradle:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.10'
testCompile group: 'org.projectlombok', name: 'lombok', version: '1.16.10'
testAnnotationProcessor "org.projectlombok:lombok:1.18.10"
}
最后,测试用例:
@Test
public void whenCheckIfPresent_thenOk() {
User user = User.builder().name("John").email("sf@sf.pl").build();
Optional<User> opt = Optional.ofNullable(user);
assertTrue(opt.isPresent());
assertEquals(user.getEmail(), opt.get().getEmail());
}
当我尝试运行此测试时,我遇到以下错误:
IdeaProjects\Tutoriale\src\test\java\optionals\OptionalsTest.java:26: error: cannot find symbol
User user = User.builder().name("John").email("sf@sf.pl").build();
^
symbol: method builder()
location: class User
IdeaProjects\Tutoriale\src\test\java\optionals\OptionalsTest.java:30: error: cannot find symbol
assertEquals(user.getEmail(), opt.get().getEmail());
^
symbol: method getEmail()
location: variable user of type User
IdeaProjects\Tutoriale\src\test\java\optionals\OptionalsTest.java:30: error: cannot find symbol
assertEquals(user.getEmail(), opt.get().getEmail());
^
symbol: method getEmail()
location: class User
似乎注解处理不起作用,但我不知道如何修复。