Module description

This site contains the up-to-date course material, exercises and announcements about PRC2 (Programming Concepts 2: the Test Driven Way), starting in February 2019.

Responsible Teachers for 2019: PRC2: Pieter van den Hombergh, Richard van den Ham and Linda Urselmans.

Study materials

Study the theory and do the tutorials before you come to class. This will make the lessons more effective for you, because the questions that you might have from studying could be answered immediately.
Studying is not glancing over some (web) pages, but experimenting with the compiler, IDE and other tools, to see if you can use the presented ideas and apply it in your own code.

Topics 2019

Week Topics

01

Test Driven, Unit Testing basics, using coverage

02

Testing and using Exceptions

03

Enums & Generics

04

Lambda Expressions/Filter, Comparator as Function

05

JDBC (Java DataBase Connectivity)

06

REST-API using Gson

07

Java FX Bindings, Java FX GUI, Architecture (Thin GUI)

08

Advanced Testing testing with mocks and parameterised testing

09

State machines / Regex/

10

Threads sockets

11

File I/O

12

Reflection

13

Roll-up and relax

You should start with the exercises in the week they are listed in and hand them in through your personal subversion repository before the start of next week’s lesson. There will be no new exercises in the final lesson week.

Slack channel(s)

For questions and answers thus documenting them and also discussions and explanations, sharing information, links and other things between students and lecturers, feel free to use the slack channel: Slack invitation link. You are only allowed to use a fontys.nl email address. Using slack is optional, but if the students share their knowledge here, this can be a helpful source and learning environment.

1. Week1 Test Driven Development

And, Oh, before we forget: Polymorphism, Interfaces, Comparator and friends, That Too (rehearsal from PRC1).

Week 1 rehearses some topics from PRC1 and introduces (unit) testing, the Java collection framework, and the Comparator as a way to make the collection very flexible.

Throughout the exercises of PRC1, your have become acquainted with the value of tests: You have a way of checking if your code is any good without having to test each and every part manually. You clicked on the nice TMC button in NetBeans and then you could see which parts of your code worked, and which didn’t. There is a catch, though: Out there in the real world, there won’t be any NetBeans button doing that magic for you, nor will a teacher of school provide the tests for you, so you are on your own. But fret not! Writing tests is typically much simpler than writing the actual code. At least, it is when you follow a basic set of steps:

  1. Prepare: set up the thing you want to test (as in, set up the experiment)

  2. Interact: execute the experiment

  3. Verify: Assert or ensure that the observable result(s) is/are as expected

On the theory of inheritance and interfaces

Oracle tutorial on Interfaces and Inheritance and Collections.

Study tutorials before you come to class or the practical session.
youtube

Slides:

1.1. Additional pointers

Start reading the fine manual (RTFM), in this case the api doc:

1.2. Demos

Lecture demo PRC2 about comparable, project in a zip. Complete the project according the tests.

1.3. Exercises


2. Testing and using exceptions

Slides:

2.2. Demos

Lecture demo PRC2 about comparable, project in a zip. Complete the project according the tests.

2.3. Exercises

2.4. Maven settings and repository

A maven repository is a server that provides ready built maven 'artifacts', such as (binary) jar files containing libraries, frameworks or APIs and in many (but not all) companion jar files containing the javadoc (often) and sources of the same binary. A maven repository is NOT a source code management system (CMS), although it typically holds several versions of a binary.

There is a default repository, called maven central. You (as a team or company) can have your own repository. We at sebi Venlo did that too. Our repository lives at https://www.fontysvenlo.org/repository. Note that only teachers can put (jar) files in that repository. If you look at that repository you will see that it is organized along the three axes: groupId, artifactId and version.

To make this repository available for your own projects, add the following to your `~/.m2/settings.xml in the profiles section. You may also want to make that profile active.

adding fontysvenlo repo to your maven settings.
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <profiles>
        <profile>
            <id>sebivenlo</id>
            <repositories>
                <repository>
                    <id>fontysvenlo.org</id>
                    <url>https://www.fontysvenlo.org/repository</url>
                </repository>
            </repositories>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>sebivenlo</activeProfile>
    </activeProfiles>
</settings>

Note that I am using an installed maven (3.5.2) which you can download from apache maven, not the one bundled with netbeans. You can tell netbeans (via tools→ options →java→maven) to use the installed one instead of the bundled one.

Doing this gives you the access to sebipom, which defines a parent pom for projects. This again provides some goodies that you would otherwise have to provide yourselves. Such a parent pom is similar to a super class in Java; your pom inherits all the traits of the parent.

Including that parent is simple. See below for the sebipom (version 1.2).

sebipom as parent.
    <parent>
      <groupId>nl.fontys.sebivenlo</groupId>
      <artifactId>sebipom</artifactId>
      <version>1.2</version>
    </parent>

Some of the starter projects we provide already use this parent. To get those working, apply the settings above.

3. Week 3 Enums & Generics

Constants with functionality and more on type safe storage.

Study the Oracle tutorial on Enum and Generics:

Slides:

3.1. Week 03 Exercises.


4. Java: Lambda & Streams, Assertion Libraries, Refactoring.

Java has additional functionalities since Java 8.

Study the oracle tutorial on Lambda and Streams:

Slides:

There is also a summary on lambda under lambdaandfunctions.html

4.1. Slides week 3 - Refactoring

Refactoring is an important task of software developers.

4.2. Study the Kaczanowski book.

In case you are missing directions for what to study from the test book (Unit Testing with JUnit and Mockito by Tomek Kaczanowski.): All of it, but not necessarily at once.
We will apply several techniques from the book during the course, mainly in the practical sessions. Of course you may ask during class if there is a topic you do not understand (yet).

Where the book uses or refers to the FEST testing library, we will instead use AssertJ, which is an up to date and well maintained and documented, rich testing library. Have a look and enjoy the clarity of the examples.

We did not add specific topics or order of topics to the study guide on purpose. For instance the way you can parameterise your test is shown in the book in several ways (e.g. in Chapter 3). We have shown that in for instance a fraction solution variant. We expect you to understand the concepts and be able to use an API (LG6, PRC2), even if this is a testing API.

4.3. Week 04 Exercises.


5. Java Database Connectivity (JDBC)

How to work with a database directly from Java in a command line, desktop or web application.

Study the JDBC Introduction.

5.1. Week 07 Exercises.


6. RESTful Java with JAX-RS

Makes development of RESTful web services in Java simple.

6.1. Sheets and handhout PRC

Sheets on Restful services with JAX-RS sheets and handout

Sheets on testing and mocking restful services . By Loek Ehren and Rick van Osch.

A Guide to REST-assured on the baeldung site. Get acquainted with the concept. We will NOT use groovy etc. For that we have the workshop.

Intro to wire mock on the baeldung website.

The wiremock website will have more info on rest mocking.

For manual rest api testing the Advanced Rest Client could be used. It is based on nodjs, electron and chromium, the same technology stack as Atom, VS-Code and more.

An alternative and nice and good looking rest inspection client Insomnia , suggested by Jordi Limpens.

logo Payara5, the preferred JEE constainer for PRC and Project 2. Payaras are related to Piranha, also a well known bad-ass fish.

Payara the bad ass fish

6.3. Rest Assured, how to post a student.

Short intro into rest assured on how it is used in the lesson demo with the fantys university grading system.

6.4. Week 08 Exercises.


7. JavaFX Bindings

7.1. Theory and slides on JavaFX Bindings.

There is a good tutorial about javafx bindings on the oracle website.

The slide set gives a summary of that.

7.2. Demos

Note that the example uses a very simple an basic way to communicate with the API, using the standard Java SE API to open a connection to a host and retrieve the payload. The example knows that the info is in json format and does not bother to specify the mediatype in the request.

7.3. Resources

The framework to show the agenda in class is from http://jfxtras.org/. You can add jfextras as a dependency to your maven JavaFx project by adding the dependency below. It has many nice widgets, in which you can apply binding to your hearts content.

jfextras dependency
<dependency>
   <groupId>org.jfxtras</groupId>
   <artifactId>jfxtras-labs</artifactId>
   <version>8.0-r6</version>
</dependency>

7.4. Java FX GUI, Architecture (Thin GUI)

The demo on the Agenda has a few flaws,

  • both business wise as well as

  • architecture wise.

Can you point them out? (Answer: it is in the architecture. Doing too much in the GUI layer makes it a badly testable design.)
The solution is to use the UI layer to improve the user experience (UX), but to keep the (final) decision in the business layer where the decision taken by said business layer can be tested. In the example, let the use move then appointments on the GUI only, but require submit or something the trigger the business acceptance method. This in the end could be as simple committing the appointments to the database, and with properly designed constraints in the database, that will in the end accept or reject the combination of appointments.

7.5. Week 10 Exercises.


8. Week intentionally left vacant.

You will have sufficient work and questions to fill up the whole week ;-)

Solutions to various exercises.