Posts

Showing posts from March, 2012

How to unit test async code with callbacks

@Test public void deleteEmployee() throws Exception {     EmployeeReqCtx reqCtx = rf.employeeReqCtx();     final boolean[] onSuccess = {false};     reqCtx.delete(10L).fire(new Receiver<Void>() {            @Override            public void onSuccess(Void response) {                  onSuccess[0] = true;            }            @Override            public void onFailure(ServerFailure failure) {                  System.err.println("failure.getMessage() = " + failure.getMessage());             }      });       assertTrue(onSuccess[0]); } The trick is to use a  final boolean array  because you need to use  values  (finals) within callbacks (inner classes) and finals are immutable so you  could not simply change a final onSuccess value to true .

E-mail address regex / regexp pattern

The whole  e-mail address  regexp pattern thing is  much  more complex than just a .*@.*  and there are  a lot  of different variations. However this one is the  HTML5 spec regex pattern : /^[a-zA-Z0-9.!#$%&amp;'*+/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/ ...as of 2012-01-10. It works well together with RequestFactory's onConstraintViolation. @Pattern( message = "Invalid mail address.", regexp = "^[a-zA-Z0-9.!#$%&amp;'*+/=?\\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$" ) private String mail;

Git: checkout / get back a deleted file w/ commit id

Problem: You've deleted a file and want to get it back but you can only remember just a part of the file name or even just a part of the comment you've assigned to the respective Git commit. Now you want this file back which you've deleted a while ago. Solution: 1. Get the id of the commit where the file was deleted using one of the ways below. git log --grep= word git log -S word git log | grep --context=5 word git log --stat | grep --context=5 word # recommended if you hardly remember anything 2. You should get something like:  commit bfe68bd117e1091c96d2976c99b3bcc8310bebe7 Author: Alexander Orlov <alexander.orlov@loxal.net> Date:   Thu May 12 23:44:27 2011 +0200     replaced deprecated GWT class     - gwtI18nKeySync.sh, an outdated (?, replaced by a Maven goal) I18n generation script commit 3ea4e3af253ac6fd1691ff6bb89c964f54802302 Author: Alexander Orlov <alexander.orlov@loxal.net> Date:   Thu May 12 22:10:22 2011 +0200 3. Now using the