Posts

Kotlin Companion Extensions and Blocks

Companion objects have been Kotlin’s answer to static members since 1.0. With Kotlin 2.5.0, KEEP-0449 introduces two new experimental features — companion blocks and companion extensions — that finally decouple “accessible through the type name” from “there is an object behind it”. After a recap of why the companion object was not quite enough, this article walks through the syntax and the use cases. Read the article on medium...

Kotlin Context Parameters

Context receivers have been around in Kotlin since version 1.6.20 in experimental state, now they have entered preview state with version 2.2.0 under the name context parameters. The experimental phase has been used to get a better understanding of the use cases, to introduce improvements and to clarify the syntax. After a recap of the evolution, this article will show some use cases and the syntax, in order to give you an impression of the possibilities offered by context parameters. Read the article on medium...

Azure Storage Development with Azurite — Part II Testing

The first part was about setting up Azurite and using it for local development, and how the Azure Storage Explorer can be helpful in interacting with the storage. In this second part we will use Azurite as a testcontainer for medium size Unit and Spring Integration tests. Read the article on medium...

Azure Storage Development with Azurite — Part I

This article will show the usage of Azurite, a lightweight server clone of Azure Storage. The first part will be on setup in order to use the BlobStorage, TableStorage and Queue-APIs, the second part will be on testing using Azurite testcontainer. Read the article on medium...

Testing Coroutines — Update 1.6.0

About one year ago I wrote some articles describing the Kotlin Coroutines Testing module. With the recent 1.6.0 release things changed significantly, so it’s time for an update. Read the article on medium...

Testing Coroutines — Dispatchers

In part one and two of this series we saw how to make use of the time control features of the kotlinx-coroutines-test module. In this part you will see how to test code that utilizes a dedicated dispatcher. Read the article on medium...

Testing Coroutines — Timeout

The first part of this series provided you an introduction to the building blocks of the kotlinx-coroutines-test module, and gave you some examples on eager execution and virtual time. In this second part we will have a look at testing timeouts. Read the article on medium .

Testing Coroutines — Introduction

This is the first part of my little series on testing coroutines, where we will explore the capabilities of the kotlinx-coroutines-test module. All examples (and some utility functions) are provided in a Git repository, so give it a try. This first part will introduce the building blocks of the module, and give some examples on eager execution and virtual time. Read the article on medium .

Getting Started With Kotlin-React

One of the hot topics of the KotlinConf 2017 keynote in San Francisco was multiplatform development with Kotlin, Kotlin/Native and Kotlin/JS. The latter has been demonstrated using the Kotlin wrappers for React, which allows you to write React apps using Kotlin. This sounds promising, since it allows you to write both (web-based) front- and backends using one language. In this three-part article on Medium I’d like to give an introduction to Kotlin-React.

JUnit 5 - Part II

Image
In the first part , I gave you a brief introduction to the basic functionality of the new JUnit 5 framework: new asserts, testing exceptions and timing, parameterizing and structuring tests. In this part I will explain the extension mechanism, which serves as a replacement for the runners and rules. The New Extension Model JUnit 4 introduced the concept of runners, which allowed you to implement a strategy on how to run a test. You could specify the runner to use by attaching the @RunWith annotation to the test class, where the value of the annotation specified the runner class to use. You could do quite a lot of stuff with runners, but they had one central drawback: you could specify only one runner on a test :-| Since this was not flexible enough for most people, they invented the concept of rules. Rules allows you to intercept the test execution, so you can do all kind of stuff here like test preparation and cleanup, but also conditionally executing a test. Additionally y...

JUnit 5 - Part I

Image
More than a decade ago I wrote an  introduction to JUnit 4 , which was – to be quite honest – just a catch-up with the more advanced TestNG. Now JUnit 5 is in the door and it is a complete rewrite, so it’s worth having a fresh look on it. In the first installment of this two part article I will describe what’s new in the basic usage: new asserts, testing exceptions and timing, parameterizing and structuring tests. JUnit 5 comes with a comprehensive user guide , most examples shown in this part are taken from there. So if you already read that, you may skip this and continue directly with the second part, which describes the new extension API that replaces the old runner and rules mechanisms. One Jar fits all? Prior to JUnit 5 all parts of the JUnit framework has been packed into one jar: the API to write tests - e.g. assertions - and the API and implementation to actually run tests; for some time, even hamcrest was baked into it. This was a problem ...

Hyperlinks with PDFBox-Layout

Image
One thing that made HTML so successful is the hyperlink. Keywords are marked up, and just by clicking on them, you are redirected to the refrerenced position in the document, or even to some totally different document. So it makes perfect sense to use hyperlinks in PDF documents also. Whether you are linking the entries of a TOC to the corresponding chapter, or a piece of information to a corresponding URL in wikipedia. Linking text enriches the content, and makes it more usable. Luckily PDF (and PDFBox ) supports hyperlinks, so why not use it? Because it's a pain. The PDF standard has no notion of marked up text, but the more general and abstract idea of annotated areas: You can describe some area in the document by coordinates, and add some metadata telling the PDF reader what to do with that area. That's quite powerful. You can do highlighting and all kinds of actions with that, and totally independant of the content, just by describing an area. And that's also the ca...

Creating Lists with PDFBox-Layout

Image
The last article gave you a brief introduction on what you can do with PDFBox-Layout. The new release 0.6.0 added support for indentation and lists, and that’s what this article is about. Indentation Indentation is often used to structure content, and it is also the base for creating lists. Let’s start with some simple example using the Indent element. paragraph.addMarkup( "This is an example for the new indent feature. Let's do some empty space indentation:\n", 11, BaseFont.Times); paragraph.add(new Indent(50, SpaceUnit.pt)); paragraph.addMarkup("Here we go indented.\n", 11, BaseFont.Times); paragraph.addMarkup( "The Indentation holds for the rest of the paragraph, or... \n", 11, BaseFont.Times); paragraph.add(new Indent(70, SpaceUnit.pt)); paragraph.addMarkup("any new indent comes.\n", 11, BaseFont.Times); So what do we do here: we add an indent of 50pt width. This indent will be automatically inserted after ea...

PDF text layout made easy with PDFBox-Layout

Image
More than a decade ago I was using iText to create PDF documents from scratch. It was quite easy to use, and did all the stuff I needed like organizing text in paragraphs, performing word wrapping and marking up text with bold and italic. But once upon a time Bruno Lowagie - the developer of iText - switched from open source to a proprietary license for reasons I do understand . So when I now had to do some PDF processing for a new project, I was looking for an alternative. PDFBox is definitely the best open source choice, since it is quite mature.But when I was searching on how to do layout, I found a lot of people looking for exactly those features, and the common answer was: you have to do it on your own! Say what? Ouch. There must be someone out there, who already wrote that stuff... Sure there is, but google did not find him. So I started to write some simple word wrapping. And some simple pagination. And some simple markup for easy highlighting with bold an italic. Don't...

Avoid Vertical Limits in Microservice Architectures

Image
The microservice architecture allows us to partition an application into tiny sub-applications, which are easy to maintain and to deploy. This pattern is already widely adopted to implement backend systems. But the frontend is usually still one large application, at least when it comes to deployment. This article describes some thoughts on how to address this problem. The microservice architecture is en vogue, everybody seems to know all about it, and feels like having to spread the truth. Including me ;-) But honestly, we are just about to learn how to cope with this kind of architecture. I guess we are like a kid that just managed to make some first steps, when we suddenly try to start running… that’s usually the moment when you fall over your own feet. Microservices are no free lunch, it definitely has its price (that’s the part we have already learned). For developers it feels uncomfortable, since instead of developing one application, they have to deal with dozens or hundreds. U...