Sequential Mockito verifications refactoring with fluent interfaces

This article was originally written in Russian and published on September 12, 2016 at Habrahabr

Static methods have one powerful and not very desirable feature: they can be invoked from any place of the code, and they also can't really dictate the order of such invocations. Usually such control is really important, but sometimes the real order does not make much sense. For example, assertions and verifications in unit tests often do not require to be executed in strict order. To ensure that all verifications are done, Mockito provides a static method named verifyNoMoreInteractions(...). Sometimes, accidentally, this method can be invoked before the last verify(...) is invoked so a bitter "red" test will be the result. But what if delegate the verification order check to the compiler?

Read more…

Making fun with Java and C preprocessor

Sometimes, usually on Fridays, there is nothing to do. And I always missed a very cool feature of meta-programming in Java. Well, Java is not very excited about making changes in the core language, so we can make some fun with meta-programming ourselves. Let's take a look at a Java and C preprocessor example. And remember, it's just for fun and nothing else. :)

Read more…

Ternary predicates authorization in Spring Security

Recently I posted an article on Spring Security describing how to make @PreAuthorize expressions custom types aware. Today I'm going to share some my codebase for ternary authorization with three possible values: GRANT, ABSTAIN, and DENY.

Read more…

A little StringBuilder drawback

Can you spot a mistake in the code below?

StringBuilder sb1 = new StringBuilder("0");
StringBuilder sb2 = new StringBuilder('1');

Read more…

When Android backup and restore tools may fail

The original question was originally posted on August 27, 2016 at Android StackExchange

Recently I've faced with a problem of migrating applications and their data from one device to another. Backing up and restoring is not a hard think, at least it should not be. However, standard Android approach may not work as expected causing weird issues. Let's take a look at one of them.

Read more…

Cracking Jewels Saga for Android

The next month marks 12 years since my first crack. I feel a kind of old. It was a nice period trying to find something new everyday. Software cracking was among them. Despite I have never been skilled in cracking and all my old cracks are quite simple, I still respect reverse engineering guys very much.

Recently I've became a fan of an Android game called Jewels Saga. I didn't use any cheats and I could reach the 198th level being stuck on the 197th level. However I couldn't walk through the level for more than a week, so...

Read more…

Spring Security @PreAuthorize annotation custom types and inspectable DSL support

This article was originally written in Russian and published on August 11, 2016 at Habrahabr

Spring Security is a must-have component for Spring applications as it's responsible for user authentication and system activity authorization. The use of @PreAuthorize is one of Spring Security methods allowing to define some authorization rules easily, and these rules can grant or deny some operation for a particular user.

The REST service I currently develop has to provide an endpoint to list all controller methods authorization rules. And, if possible, avoid revealing the specifics of SpEL expressions (so, use something like anybody instead of permitAll; avoid principal at all as an excessive expression), but return custom expressions we can process whatever we want.

Read more…

Java 8 libraries and Android applications using Maven

The original question was originally posted on May 17, 2015 at StackOverflow

This article was originally written in Russian and published on September 15, 2015 at Habrahabr

Java 8 was released in early 2014 featuring some pretty convenient new features to simplify trivial coding and letting the developers to simplify their lives. Some of them are lambda expressions, method and constructor references, interface default methods as the Java language and JVM extensions, and the Stream API for JDK. Unfortunately, slow introduction of such new features has a pretty negative impact on another Java-oriented platforms. GWT and Android still lack the Java 8 language features official support. However, the last spring GWT 2.8.0 SNAPSHOT versions have lambda expressions support already. Android things are still different since lambda expressions rely on the Android Java runtime, and not just the compiler. But Maven 8 lets to solve the Java 8 use problem relatively easy.

Read more…



I hate S.O. morons

The post originally was posted on 2019-03-22 07:43:00 +0300, but it has been two years since then, so I don't really care now.

I refused to contribute to StackOverflow a year ago. Yeah, I still have peeked into the Gson tag hole anonymously. That was the power of the gamification I lived with almost a decade. Okay, I never contributed heavily, however I wouldn't let myself post a stupid answer trying to put the best I can for those morons for free. Yeah, that is. Sometimes I posted under fictional names (see idontcare and no-one-cares users there if you want), because I had a feeling I had to make a post, probably being a gamification addict. Come on, what's for? I don't know, let it go away. Recently I decided to help out a folk with 120+K reputation. Explaining why his deserializer is not invoked, why he's using a raw class and why it's wrong, referenced my own PR to Gson addressing a similar issue, I got a negative reputation point. After 20 minutes since I posted my answer, the OP posted my own PR calling it a feature released in Gson 2.8.5 (again, this is wrong and this is a stale PR not have yet been released). OP, what's wrong with you? I'll never post to StackOverflow anymore even anonymously leaving all the morons with their problems alone. Fuck it.