RSS Feed Subscribe to RSS Feed

 

Getting rid of IntelliJ warning: Local variable is redundant

When dealing with a piece of code like this

    String id = "abc";
    return id;

IntelliJ may give a warning message:

    Local variable 'id' is redundant

I can see IntelliJ’s point. The code could be rewritten as follows:

    return "abc";

However, sometimes it can be useful to use a variable name as a form of documentation.
Also, and more often, I don’t want to see this warning pop up for other people’s code! If they wish to use a “redundant” variable, who am I to argue? I certainly don’t want to be warned about it every time I do a commit.

To disable this warning, deselect the following:

Preferences -> Editor -> Inspections (-> Java) -> Data flow issues -> Redundant local variable -> Ignore immediately returned or thrown variables

Or you can setup custom handling for tests (e.g. weak warnings) under Severity by Scope.
(Based on IntelliJ 15)

Tags:

Chrome Keyboard Shortcuts

I typically use Chrome as my browser of choice, and it comes with a plethora of keyboard shortcuts that I find incredibly useful and use constantly. However there are ways to add to those shortcuts too, including a tool called Vimium…

(more…)

Tags: , , ,

Running tests in IntelliJ for a multi module maven project

This post shows how to run all the tests in IntelliJ for a multi module maven project.

(more…)

Tags: , , ,

Unit Testing – the Hard Parts @ NYC Code Camp

Thanks to everyone who came to my “Unit Testing – the Hard Parts” presentation @ New York Code Camp. I really enjoyed it! Great crowd, lots of follow up questions. And cool Microsoft office space in Times Square. Thank you to all who attended. My slides are here: http://www.slideshare.net/shaunabram/unit-testing-the-hard-parts

Tags: , , , , , , , , ,

Test Doubles: mocks, dummies and stubs

Most classes have collaborators. When unit testing, you usually want to avoid using real implementations of those collaborators to avoid test brittleness and binding/coupling, and instead use Test Doubles: Mocks, Stubs and Doubles.

This article references two existing articles on the subject: Mocks Aren’t Stubs, by Martin Fowler and The Little Mocker, by “Uncle” Bob Martin. I recommend them both.

 

(more…)

Tags: , , , , , , , , , , ,

Testing private methods in .Net

Feeling the need to test private methods is usually a sign that your code needs refactoring. The recommended approach is that you test your code via it’s public interface. Since your private methods are only accessible via those public methods, it goes that if you have thoroughly testing via the public interface, your private methods will have been tested too.

Still, there can be times testing private methods can be useful. For example, while dealing with either legacy code or when using it as a temporary step while refactoring.

How do you do this in .Net?

(more…)

Tags: ,

Docker talk at SVCC’15

Some short notes from a talk from Ted Young on the Docker ecosystem. Slides available here.

BusyBox – a number of use linux tools packaged up in to a single file. “The Swiss Army knife of Embedded Linux”

CoreOS and Red Hat’s Atomic are particularly suited for running containers, work well with (and I think even come preinstalled with) Docker.

VM vs Container. VMs ofter have multiple apps running in them (e.g. a tomcat with multiple apps running it int). With containers it is typically 1 app per container. Containers typically run within a VM (although can run on “raw metal” too). Multiple containers per VM? – I’m not so clear on!

Cgroups may be used to limit and control resource usage.

12 Factor apps – Good practices for building “cloud native” or software-as-a-service apps.

 

Tags: , , , ,

Git talk at SVCC’15

Some short notes from a talk on “Everything you wanted to know about Git…” by Lenny Markus. Slides available here.

Tips:

Use autocomplete

Use the latest git tool, not the apple default

As part of the demo, he used watch to monitor a directory by running a command every few secs.

Covered git init, staging, reset and rebasing.

 

 

 

Tags: , ,

RESTful Microservices at Silicon Valley Code Camp ’15

Thanks to everyone who came to my RESTful Microservices talk at Silicon Valley Code Camp today. Great turnout and lots of good follow up questions.

You can find the complete slides on slideshare.

Tags: , , , , , , , , ,

Java vs .Net Accessor Modifiers

I’ve been looking at some .Net code recently, and I wanted to do some comparisons on Java access modifiers vs .Net to help me better understand the code.

(more…)

Tags: , , ,