Posts

Tip (Spock): Don't Use .each in a then block!!!

This happens time and time again. QA finds a bug and I swear I wrote a test for that condition. So, I go back to try and write a failing test.  I see the original test I wrote and the condition that should fail.  It looks something like this:

when: List<SomeType> someResults = service.someAction(someParam) then: someResults // assert the result is not null, empty list, etc someResults.each { it.someFieldName == 'someValue' it.someOtherFieldName == 1 }
In this case, someOtherFieldName is empty but the test still passes... wtf?! right?

Well, this is actually the expected behavior.

Because .each doesn't actually return anything, Spock thinks it is fine.  It doesn't care about the lines within each block and whether they fail or not.

So we have two choices here:

use .every instead of .each when: List<SomeType> someResults = service.someAction(someParam) then: someResults someResults.every { it.someFieldName == 'so…

Tip: Reverse Sorting in Groovy

One of the great things about Groovy is that there are multiple ways to get **it done. This means people learning Groovy and especially those coming from other programming languages can use the same syntax and practices they are already familiar with. However, this may result in some small mistakes or inefficiencies.

The first one I want to highlight today is reverse sorting.

So given:

class Person { String name Integer age }
If we want to sort a list of people by their age, we would normally use:

people.sort { it.age }
To reverse the list, we have several options including:

people.sort { it.age }.reverse()
or:

people.sort { -it.age }
The first one, I see a lot. It's easy to write and to think about, but it's not as efficient as the second one. Why sort the list and then reverse it, when you can sort by the criteria you want in the first place?

The next problem comes with the '-' notation. It works great for examples like this when we are sorti…

No, It wasn't just about the travel

I haven’t talked about this for various reasons. From the comments I’ve received in the last week, it seems like continuing to hint at what happened rather than talking about it, and embarrassing people(myself included) has actually made the situation worse so here’s a collection of everything that happened from my point of view.
The First Blog Post (Early March) So let’s begin with a blog post I published back in March.  The version there right now is not the original.  Originally, I had included a case study based on a conversation from Twitter about the low number of women who were applying at Gradle, Inc. I thought I was helping by showing that it wasn’t just a problem with Gradle, but in the entire community and trying to think of reasons why the numbers might be so low. Within 45 minutes of posting it, I had three different people harassing me via various communication methods about how it might be viewed as an attack on Gradle, Inc.  I had a lot of respect for the members of t…

Isn't promoting women through these organizations, preferential hiring, and funding opportunities depriving males of the same opportunities?

Note: I'm publishing this now, even though I wrote most of it over a year ago when I was working on the Diversity 101 series. At the time, I was really burned out. I was struggling with issues at work and in the community, and the feedback I got from some of my readers was that they felt there was nothing they could do to help improve the conditions since they weren't doing anything wrong and every time I brought up the numbers, it was just depressing. The sentiment is still true today, but perhaps we can revive the effort and work together to change it.IntroductionIn short, it shouldn't be. The purpose of diversity organizations isn't to create an unfair advantage but rather for equality. In fact, I get rather annoyed when individuals or articles claim "Girls are better at .. X". I fall outside many of the generalizations about my gender and find that most stereotypes have little to do with that and more to do with personality traits or confounding variabl…

Women in Groovy Open Source Projects

Image
After many recent announcements about the abuse of women at different companies in our industry, I saw a thread on Twitter about encouraging and supporting women in tech.  There was one aspect of a tweet though that got me thinking about the percentage of women applicants at several companies who use Groovy and related technologies.  My first thought was that maybe it was a lack of applications in general or perhaps even an HR screening problem so I started to look for how many women might apply for a job based on prior knowledge and contributions to open source projects. For each project, I looked through the list of top contributors on Github.


As I searched through the list, I saw a depressing pattern.  My prior work with company data shows that only about 5% of Groovy developers are women. That number is consistent with conference attendance at Groovy conferences. I also know that when we look at other programming language communities, we typically see an even smaller number of wom…

Using Spring REST docs to document a public API

Image
During my talks last year about Spring REST docs, I was frequently asked if I could use Spring REST docs to document other APIs. I always thought it was possible, but now I have a working example.  I was able to configure RestAssured to poll a public demo API,  JSON Placeholder, and use those snippets to form API docs.

The demo repository is available at https://github.com/jlstrater/spring-boot-restdocs-public-api-example, and the docs are published at https://jlstrater.github.io/spring-restdocs-public-api-example

The rest of the example is similar to any other Spring REST Docs example, but the configuration is slightly different:


In figure 1, the third line specifies the URL to run against.  This will also affect the generated snippets as seen in Figure 2. This shows how it will use the real address instead of localhost like it would for a local example.


Conclusion
This could be useful for documenting parts of a system, you may not have direct access to, or for highly complex systems …

Fulbright Update November 2016

As I near the three-month mark of my Fulbright grant, I reflect back on my experience thus far. Although I had a rough start with government paperwork and finding housing, I am now finally starting to experience life in Denmark. Adjusting has taken some time as I have learned how to bike with traffic and find the most efficient route to take public transportation between my apartment on the far southwest side and the university north of the city.

For the educational aspect of my Fulbright experience, I am taking four classes this semester and one in January that will lead into my project work in February.  Every few weeks, I meet with my advisor to discuss how my coursework will impact my project in the Spring.  I also had a minor advisory role in the selection of a master’s thesis with the Groovy compiler for another student.  Students and professors have been mostly positive and open minded when I talk about the Groovy programming language. Some are familiar with Groovy from using …