Sara

Context :

With my team I am developing a feature that can calculate weekly, monthly, yearly reports. After pulling the develop-branch on my computer, multiple tests went haywire. Tests for weekly reports had been added and those failed on my computer because of week numbers. After checking with all colleagues (Mac-users) and the Jenkins jobs that run all tests after commit (running on Unix) it seemed my Windows was the only one with failing tests.

So lets look at one of the failing tests :

        assertThat(row16.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2017-52");
        assertThat(row16.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);
        assertThat(row17.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2017-53");
        assertThat(row17.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(1.0);
        assertThat(row18.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2018-1");
        assertThat(row18.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(6.0);
        assertThat(row19.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2018-2");
        assertThat(row19.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);

Result :

        org.junit.ComparisonFailure: 
        Expected :"2017-53"
        Actual   :"2018-1"

What was happening :

Different countries have different time/date standards :

  • The calendar that is used.
  • The order in which the year, month and day are represented.
  • How weeks are identified (see seven-day week)
  • Whether written months are identified by name, by number (1–12), or by Roman numeral (I-XII).
  • Whether the 24-hour clock, 12-hour clock or 6-hour clock is used.
  • The punctuation used to separate elements in all-numeric dates and times.
  • Which days are considered the weekend.

My machine was using the settings from Great Britain, and my colleagues were using different settings. Meaning our week starts on different days(Sunday / Monday) and our year had a different amount of weeks due to this. My year only had 52 weeks. Their years consisted of an additional incomplete week with the last/first days of the year.

Iso standards : Wikipedia can give you a very dry explanation of how it all works, but just trying a few 31/12/YYYY on an ISO conform time converter can show you how it works.

If the week contains 4 or more days in year X, the week is in year X.Image description

Image description

How we fixed it :

Since we work for an international company we will have to implement a standard, and communicate this to all that use our API. We chose to use the settings from Great Britain, meaning that 2017 only has 52 weeks. Weeks should have 7 days, and should start on a Monday. Fully in line with the ISO standards.

To set the locale settings on the local servers and maven we used this :

         -Duser.language=en -Duser.country=GB

The tests were adapted to test if ISO standards and GB locale is used :

        assertThat(row2.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2017-38");
        assertThat(row2.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);
        assertThat(row16.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2017-52");
        assertThat(row16.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);
        assertThat(row17.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2018-1");
        assertThat(row17.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);
        assertThat(row18.getCell(CONSOLIDATE_DATA_WEEK_COLUMN).getStringCellValue()).isEqualTo("2018-2");
        assertThat(row18.getCell(CONSOLIDATE_DATA_WEEK_COLUMN + 1).getNumericCellValue()).isEqualTo(7.0);

Tip of the day :

Because you are the only one having the bug, it's not a given that the issue is on your machine.

Because you are a minority, it does not mean you are wrong.

Sara

I spend 3 full days looking for a bug during my Spring 3 to Spring 4 migration at work, and finally found the issue:

Spring 3 will autowire beans on the ClassName,Spring 4 does this on the full.package.name.ClassName.

In the controller I was calling

Image description

and in my mapper was this :

Image description

The a.b.c.Languages was an interface, and unfortnuately the implementation, x.y.z.Languages is called the same.Making it very hard to find the issue.

The full stackOverflow post

Sara

Spring is a fantastic open source framework that addresses the complexity of application development. One of the chief advantages of the Spring framework is its layered architecture, which allows you to be selective about which of its components you use. Spring is a cohesive framework for J2EE application development.

While developing desktop, web, enterprise, cloud, or microservices applications, almost every application type needs a robust infrastructure which takes care of dependencies, auto-configuration, and actuators.

So getting started with Spring or any other frameworks is a critical and time consuming task.Spring provides a convenient way over such application infrastructure issues with a framework called Spring Boot.Spring Boot provides the best industry practices, helps when you start applications from scratch, and boosts your application development speed.

Full tutorial >>

Image description

Image description

Sara

When you first think about becoming a software developer, you probably have dreams of creating exciting new features, playing with new technologies, and writing some really cool and interesting code. What you probably don’t think about is working on a 10-year-old, crufty application written by some guy who left the company a long time ago, fixing the bugs he left behind.

Article content :

  • Great Developers Write Maintainable Code
  • The Boy Scout Rule “Leave the campground cleaner than you found it.”
  • Readability Is of Utmost Importance
  • Refactor Code to Make It Better
  • Automation Is Essential
  • If You Write Comments, Write Good Ones
  • Use resources for Learning to Write Maintainable Code

Image description

Sara

Personal experience:

I have been working with TDD for the past two days and it is confusing me. There are a lot of reasons why this is the way to go, I am given a legacy project that no one has touched since 2011 and has no test-coverage whatsoever. To make sure I don't break everything I write tests before touching any of the code. Once the entire class is covered and has the proper fixtures, I can get started! Normally I would dive in the code but I am pair programming so ... adapting to my partner it is. He writes his tests first, and tries to write the minimal amount of code to get the test to pass. Sounds wonderful, but is completely against anything I have ever done. I have to temper myself not to go changing the code before my test is failing, yes failing. Just when that happens I am allowed to write code again.

I am having a hate love situation here. I love the security and the clean code. But tempering my code-enthusiastic fingers is not easy at all. Test driven development will take some time to get used to.

Image description

Sara

So this is a tool I have been using some time. You remember the days when you just hated any school project? Well Hackerrank is like a school project. The goal, the requirements and the restrictions are given and off you go. There is even a test at the end, or in most cases multiple tests. This way you are encouraged to write so generic code as possible. In my opinion this is the best way to quickly gain code experience. Student-me would have called me crazy. Work-me likes to learn new and better ways to code. Not just my beloved Java, but scala, ruby, ... The website provides multiple disciplines and languages to practice.

I have tried multiple of those 'learning-websites' where you cna practice your coding skills, Hackerrank is my personal favourite. It is straight forward, still feels like coding and has different skill levels.

Image description