Posts

Showing posts from May, 2014

In-Depth Understanding JUnit Tests

Source code on GitHub public class ExampleTest {     private static final Logger LOG = LoggerFactory.getLogger(ExampleTest.class);     /**      * This method won't be executed if the unit test will be (externally) terminated (e.g. from within the IDE).      * You have to act **really** fast in this case.      */     @BeforeClass     public static void beforeClass() throws Exception {         LOG.info("@BeforeClass"); // will be always executed, even if a test fails throwing any Exception     }     /**      * This method won't be executed if the unit test will be (externally) terminated (e.g. from within the IDE).      */     @AfterClass     public static void afterClass() throws Exception {         LOG.info("@AfterClass"); // will be always executed, even if a test fails throwing any Exception     }     /**      * This method won't be executed if the unit test will be (externally) terminated (e.g. from within the IDE).      * You hav

Profilers for Java & Java8 w/ Very Low Overhead

Both are part of the official JDK8 package and don't need any further plugins to get started. Java Mission Control (jmc) is a production system ready profiler from Oracle that has an overhead of <1% and is suitable for profiling production systems Location: $JAVA_HOME/bin/jmc JVisualVM (jvisualvm) is a profiler for Oracle that is good enough for resolution of most issues that required a profiler, a nice profiler for getting started  Location: $JAVA_HOME/bin/jvisualvm

Builder Pattern in Java

The builder pattern can be used to provide a kind of virtual dynamically extendable constructor to build e.g. a model class for RESTful requests where not all fields are required but many fields are optional. public class ClientRequestModel {     private String url;     private String headers;     private String parameters;     private String body;     public ClientRequestModel(Builder builder) {         url = builder.url;     }     public String getUrl() {         return url;     }     public String getHeaders() {         return headers;     }     public String getParameters() {         return parameters;     }     public String getBody() {         return body;     }     @Override     public String toString() {         return url;     }     public static class Builder {         private String url;         private String headers;         private String parameters;         private String body;         public Builder url(String url) {             t

How to Assure Code Quality & Standards

Image
Code quality is an essential part of reliable high quality software where malfunctions — once they occur — can be detected and resolved quickly. To achieve a high level of software quality, certain conditions must be established to make quality not only a result of high effort and engineering passion but the result of an explicit systemic rule set.  There are several ways for  automated  code quality assessment and validation. For JVM (Java Virtual Machine) languages there are two ways to facilitate automated code analysis: Using  static byte code based analyzers like  FindBugs , that look for (anti-) patterns in the compiled JVM language code. The advantage of this tool is that it is suitable for polyglot environments and is JVM language agnostic. On the one hand it can detect issues other kind of tools cannot (e.g.  UCF_USELESS_CONTROL_FLOW ), on the other hand it  depends on a specific class file format  that is different in every major JVM release. And so far (16-05-2014)  su

Meaning of UML diagram symbols

Image