Wednesday, 25 December 2019

Improper Use of Softly Asserts

I don't really like Softly Asserts, and I notice that a lot of developers at work seem to use it all the time.

And since it's Christmas today (Merry Christmas!), let's get into the spirit of the season by testing if there is a Miracle on 34th Street.

We are going to use SoftlyAssertions with the following test written below:

And it looks fine if the tests run properly.

But when the tests fail, likely as not we see NullPointerExceptions instead of useful asserts.

Let's try to fail the test, by removing the town.

Street thirtyfourthStreet = new Street("34th Street", null);

And lo and behold, we get this:

java.lang.NullPointerException at com.mrbear.testingtests.SoftlyAssertionTest.testMiracleAt34thStreet(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.testng.internal.MethodInvocationHelper.invokeMethod(
at org.testng.internal.Invoker.invokeMethod(
at org.testng.internal.Invoker.invokeTestMethod(
at org.testng.internal.Invoker.invokeTestMethods(
at org.testng.internal.TestMethodWorker.invokeTestMethods(
at org.testng.TestRunner.privateRun(
at org.testng.SuiteRunner.runTest(
at org.testng.SuiteRunner.runSequentially(
at org.testng.SuiteRunner.privateRun(
at org.testng.SuiteRunnerWorker.runSuite(
at org.testng.TestNG.runSuitesSequentially(
at org.testng.TestNG.runSuitesLocally(
at org.testng.TestNG.runSuites(
at com.intellij.rt.testng.RemoteTestNGStarter.main(

I really would like for SoftAssertions to only be used during checking of simple properties within an object, thanks!

And not this cross-boundary stuff.

Thursday, 19 December 2019

Java Alternatives in Fedora Core - Followup

This is a followup of the blogpost Java Alternatives in Fedora Core.

The instructions in the blogpost also hold for Java 13.

[root@localhost ~]# dnf install java-13-openjdk
[root@localhost ~]# dnf install java-13-openjdk-devel

Unfortunately, there was a snag with Maven, so I thought I'd document it here.


Maven stubbornly remained firmly pointing to java 8, whatever alternative I picked in my Fedora Core.

[mrbear@localhost ~]$ mvn -version
Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 1.8.0_232, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.3.11-200.fc30.x86_64", arch: "amd64", family: "unix"

Well, trying to compile a java application with version 13 in the pom.xml, is NOT going to work when your Maven is using openjdk 8.

Really no surprise there.

You get:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project mrbearapp: Fatal error compiling: invalid target release: 13 -> [Help 1]

It turns out I really need to set JAVA_HOME?

Editing .bashrc to add the following:

export JAVA_HOME=/usr/lib/jvm/java-13

Now I get:

[mrbear@localhost ~]$ mvn -version
Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 13.0.1, vendor: N/A, runtime: /usr/lib/jvm/java-13-openjdk-
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.3.11-200.fc30.x86_64", arch: "amd64", family: "unix"

All is as it should be, and we are merrily on our way.

Thursday, 12 December 2019

Installing Bootstrap with NPM

I thought it would be a good idea to write this stuff down. You can easily find sources on the web that indicates the same instructions.

Bootstrap contains some css files and some js files.

Bootstrap also uses some optional dependencies.

Make sure NPM is the latest

npm install -g npm

Make sure your Bootstrap1 is updated and/or installed with npm.

npm install bootstrap --save

You will probably see some warnings regarding bootstrap:

npm WARN bootstrap@4.3.1 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.3.1 requires a peer of popper.js@^1.14.7 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/webpack-dev-server/node_modules/fsevents):

Install the jquery2 if you like.

It provides Bootstrap with some additional behaviour that can be initiated by the websurfer.

npm install jquery --save

Install popper.js3 if you like.

It's for popovers and tooltips and things.

npm install popper.js --save

I also use bootswatch4 for the amazing Bootstrap themes that they have.

npm install bootswatch --save


As I am using Angular5, I need to add it so Angular adds it to the app.

Add in angular.json:

"styles": [
"scripts": [

This is the way I have added Bootstrap, but there are a lot of other ways to install Bootstrap into an Angular app.

I could have added the links to the css and the javascript in the index.html file instead, but this way it gets packaged and minified into the app.

The blog post on [5] helped me a lot.

The way I am using, is not necessarily the right way. Here are some other ways to use Bootstrap with Angular.

use NgBootstrap6
I personally chose not to go this route, as it means spilling a lot of Bootstrap-specific stuff into my typescript code.
use ngx-bootstrap7
Basically has the same ideas as NgBootstrap


[1] Bootstrap - Getting started 3.4
[2] JQuery
[3] Popper.js
[4] Bootswatch - Themes for Bootstrap
[5] Using Bootstrap with Angular
[6] NgBootstrap
[7] ngx-bootstrap

Thursday, 5 December 2019

Uploading a file in Angular

I wanted my users to have the ability to upload an image via de Angular App that I provide for them.

So let me explain the process.

First, of course, there's the HTML that needs to be added to support File Uploads.

You can add these to your app.component.html file.

Then, once it is submitted it needs to be handled by your Angular app, in the app.component.ts file.

Then it gets transmitted to your rest service on the backend.

And that stashes it into the database using JPA.

All done.


StackOverflow - Angular File Upload
StackOverflow - Angular 5: How to upload an image