Skip to content

Instantly share code, notes, and snippets.

@indrekots
indrekots / verify.java
Created January 11, 2014 21:47
verifying behavior with Mockito
UserService userService = new UserService();
UserDao userDao = Mockito.mock(UserDao.class);
userService.setUserDao(userDao);
User user = new User("Luigi");
userService.registerNewUser(user);
Mockito.verify(userDao).save(Mockito.any(User.class));
@indrekots
indrekots / verityTimes.java
Created January 18, 2014 11:14
Verifying the number of times a method is called with Mockito
Mockito.verify(userDao, Mockito.times(2)).save(Mockito.any(User.class));
@indrekots
indrekots / argumentCaptor.java
Last active January 4, 2016 09:29
How to capture values with ArgumentCaptor
UserDao userDao = Mockito.mock(UserDao.class);
ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
Mockito.verify(userDao).save(captor.capture());
//do some testing logic, eg. call save on a userService object,
//which internally uses userDao to save the user object
//get the user as it was passed to the save method in userDao
User user = captor.getValue()
//
// SmoothScroll for websites v1.2.1
// Licensed under the terms of the MIT license.
//
// You may use it in your theme if you credit me.
// It is also free to use on any individual website.
//
// Exception:
// The only restriction would be not to publish any
// extension for browsers or native application
public class BookFilterRunner {
public static void main(String[] args) {
//create a list of books
List<Book> books = new ArrayList<>();
books.add(new Book("Moby Dick", 250, "Herman Melville"));
books.add(new Book("Alice's Adventures in Wonderland", 190, "Lewis Carrol"));
books.add(new Book("Sylvie and Bruno", 400, "Lewis Carrol"));
//filter a list of books
filterBooks(books, "Lewis Carrol");
@indrekots
indrekots / mass_aspect_ratio_fix.md
Created September 21, 2016 15:48
How to mass update image files and fix their aspect ratio
  • Find all image files
find . -type f -name "*.jpg" > images
  • Determine if image file is portrait or landscape
find . -type f -name "*.jpg" -exec sh -c "identify -ping -format '%W/%H>1' {} | bc -l" \; > aspect