use of com.stackify.models.User in project tutorials by eugenp.
the class DynamicTests method dynamicUserTestCollection.
@TestFactory
public Stream<DynamicTest> dynamicUserTestCollection() {
List<User> inputList = Arrays.asList(new User("john@yahoo.com", "John"), new User("ana@yahoo.com", "Ana"));
Function<User, String> displayNameGenerator = (input) -> "Saving user: " + input;
UserDAO userDAO = new UserDAO();
ThrowingConsumer<User> testExecutor = (input) -> {
userDAO.add(input);
assertNotNull(userDAO.findOne(input.getEmail()));
};
return DynamicTest.stream(inputList.iterator(), displayNameGenerator, testExecutor);
}
use of com.stackify.models.User in project tutorials by eugenp.
the class UserDAO method findAll.
public List<User> findAll() {
List<User> users = new ArrayList<>();
try (Connection con = ConnectionUtil.getConnection()) {
String query = "SELECT * FROM users";
PreparedStatement pstmt = con.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
User user = new User();
user.setEmail(rs.getString("email"));
user.setName(rs.getString("name"));
users.add(user);
}
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
return users;
}
use of com.stackify.models.User in project tutorials by eugenp.
the class UserDAO method findOne.
public User findOne(String email) {
User user = null;
try (Connection con = ConnectionUtil.getConnection()) {
String query = "SELECT * FROM users WHERE email=?";
PreparedStatement pstmt = con.prepareStatement(query);
pstmt.setString(1, email);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
user = new User();
user.setEmail(rs.getString("email"));
user.setName(rs.getString("name"));
}
} catch (SQLException exc) {
logger.error(exc.getMessage());
}
return user;
}
use of com.stackify.models.User in project tutorials by eugenp.
the class MyServiceTest method testService.
@Test
public void testService() {
MyService myService = new MyService();
User user = new User("John", "john@yahoo.com");
user.setDateOfBirth(LocalDate.of(1980, Month.APRIL, 20));
logger.info("Age of user {} is {}", () -> user.getName(), () -> myService.calculateUserAge(user));
}
Aggregations