-
Mockito: doReturn vs thenReturn
In Mockito, you can specify what to return when a method is called. That makes unit testing easier because you don’t have to change existing classes. Mockito supports two ways to do it: when-thenReturn and doReturn-when. In most cases, when-thenReturn is used and has better readability. User user = Mockito.mock(User.class); when(user.getName()).thenReturn("John"); However, sometimes you need to consider using doReturn-when because...
-
Checkstyle: Unable to create a Checker: configLocation, classpath {null}
Checkstyle helps developers write a solid code by adhering a coding standard. You can modify the configuration file to apply defined rules or to add your own rule. After changing the config file, you would run checkstyle task to see the changed behavior. If something is wrong, you will see this error message like this: $ ./gradlew checkstyle Parallel execution...
-
Checker for Static Import
When you write code, it is vital to keep consistency. It makes better readability and maintainability. It is easier when you work alone. However, it would be hard to keep it when many engineers work on the same project. Checkers are fit well for this situation. Among many consistency points, let’s see how to keep consistency on a static import....
-
Mockito Answers
In Mockito, the most common way to create a mock object is to use either @Mock annotation or Mockito.mock method. When a method having a return value is called for a mock object, it returns an empty value such as 0, empty collections, an empty string, and null. @Mock private ConnectionInfo connectionInfo; @Before public void setUp() { MockitoAnnotations.initMocks(this); } private...
-
Syntax Highlighting in Jekyll
Jekyll has powerful support for syntax highlighting to show code snippets better. By default, Jekyll utilizes Rouge, which is a pure ruby-based code highlighter. Rouge can highlight 100 different languages. Thus, you don’t have to worry about how to set up something for syntax highlighting. How to Use When you want to show the code snippet, you can enable syntax...
-
Random Related Posts in Jekyll
Related posts are suggestions that could be interesting for readers who read the current post. This is quite useful since users can find more relevant content easily. Related Posts vs Recent Posts In Jekyll, there is a site.related_posts variable. Using it, related posts are rendered. This sounds simple. However, if you look closer the result, you can notice that it...