User.java package com.example.study.model.entity;
//import com.example.study.model.enumclass.UserStatus; import lombok.*; import lombok.experimental.Accessors; import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedBy; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import java.time.LocalDateTime; import java.util.List;
@Data @AllArgsConstructor @NoArgsConstructor @Entity
@Accessors(chain = true) public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String account;
private String email;
private String phoneNumber;
private LocalDateTime createdAt;
private String createdBy;
private LocalDateTime updatedAt;
private String updatedBy;
}
UserRepositoryTest.java
package com.example.study.repository;
import com.example.study.StudyApplicationTests; import com.example.study.model.entity.User; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime;
public class UserRepositoryTest extends StudyApplicationTests {
//Dependency Injection(DI)
@Autowired
private UserRepository userRepository;
@Test
public void create(){
//String sql = insert into user (%s ,%s,%d) value(accout,email,age)
User user=new User();
user.setAccount("minit");
user.setEmail("[email protected]");
user.setPhoneNumber("010-1111-1111");
user.setCreatedAt(LocalDateTime.now());
user.setCreatedBy("admin");
//User newUser = userRepository.save(user);
//System.out.println("newUser:"+newUser);
}
public void read(){
}
public void update(){
}
public void delete(){
}
}
Error message /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:21: error: cannot find symbol user.setAccount("minit"); ^ symbol: method setAccount(String) location: variable user of type User /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:22: error: cannot find symbol user.setEmail("[email protected]"); ^ symbol: method setEmail(String) location: variable user of type User /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:23: error: cannot find symbol user.setPhoneNumber("010-1111-1111"); ^ symbol: method setPhoneNumber(String) location: variable user of type User /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:24: error: cannot find symbol user.setCreatedAt(LocalDateTime.now()); ^ symbol: method setCreatedAt(LocalDateTime) location: variable user of type User /home/nakazaki/IdeaProjects/study/src/test/java/com/example/study/repository/UserRepositoryTest.java:25: error: cannot find symbol user.setCreatedBy("admin"); ^ symbol: method setCreatedBy(String) location: variable user of type User 5 errors FAILURE: Build failed with an exception.
This is it, and even if I annotate the one in the create() statement above, an error appears
spring-boot
Inject the bean from the spring container. Don't say new User.
Please refer to the link below for how to test using spring-test.
© 2024 OneMinuteCode. All rights reserved.