How to avoid package clashes when using Android with Mockito and Dexmaker.
It’s a real pain the get Mockito, Dexmaker and Dexmaker-Mockito running with Android. I run into a lot of packages clash problems like:
|
1 2 3 4 5 6 7 8 9 10 |
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION: [INFO] java.lang.IllegalArgumentException: already added: Lorg/hamcrest/BaseDescription; .... [INFO] UNEXPECTED TOP-LEVEL EXCEPTION: [INFO] java.lang.IllegalArgumentException: already added: Lorg/mockito/AdditionalAnswers; [INFO] at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123) ..... [INFO] UNEXPECTED TOP-LEVEL EXCEPTION: [INFO] java.lang.IllegalArgumentException: already added: Lorg/objenesis/instantiator/basic/AccessibleInstantiator; ..... |
The problem is that JUnit from version 4 or above include hamcrest within its code so you cannot even exclude it. But using Junit 3.8.2 doesn’t solve the Mockito package clashes. [...]
How to create multiple Android apk files from one codebase organized by a Maven multi module project.
This tutorial describes how to create a maintainable Android project to produce several apks for different versions of your project by using the same codebase. So you can generate a “lite” version, a “pro” version, or whatever you want, without copying and modifying whole projects. In this tutorial we create a codebase and two subprojects [...]
How to avoid java.lang.TypeNotPresentException: Type [unknown] not present Caused by java.lang.NoClassDefFoundError
In my Android project I came to strange problems when I tried to run a test with a mocked class by “Run As -> JUnit test” which extends android.app.Application. I have got exceptions like java.lang.TypeNotPresentException: Type [unknown] not present Caused by java.lang.NoClassDefFoundError: android/app/Application This is because Eclipse doesn’t know that this project is organized by [...]
How to replace private methods under test.
Sometimes you get to a situation where you hit the wall when you try to test some special algorithm. In such cases you don’t come further with usual testing concepts. At that case, people mean that a redesign of the class is necessary to be able to test it. This often leads to situations where [...]
Java: true == false
If you want to have fun with some Java code, execute this example.
|
1 2 3 4 5 6 7 8 |
public class TrueIsFalse { public static void main(String[] args) { if (false == true) { //true is false due to magic characters: \u000a\u007d\u007b System.out.println("true is false!"); } } } |
You will see that true is really false :) Hint: This works because unicode characters are preprocessed. Moreover, the syntax higlighter of Eclipse shows you that there is just a comment, but actually it is a comment, a line feed, a [...]
How to create own autocomplete Java shortcuts in Eclipse (Juno).
You probably know about those helpful autocomplete shortcuts in Eclipse. Let’s say you type syso in editor and press CTRL + Space, you will get System.out.println();. In Eclipse you can make your own shortcuts which is very easy. Go to Window->Preferences->Java->Editor->Templates and press New. You will get the following window. In my example below, I’d [...]
How to access a resource in a static context (with JUnit test example)
In a JUnit test, you often load resources in the test case setup, that means in a static context. It’s even more convenient when you are using FileUtils to do that. To get FileUtils (with version 2.0.1), add the following dependency to your pom.xml (if you are using Maven).
|
1 2 3 4 5 |
<dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.0.1</version> </dependency> |
Reading the resource, which is [...]
Unexpected token END OF FILE at position 0
As I let JUnit tests run in my Android project the first time, I came across this error: Unexpected token END OF FILE at position 0. The solution was pretty simple. I just had to run mvn install to get rid of it.
Eclipse Juno: How to change the blue tabs in classic theme.
Due to a package update of my Eclipse Indigo I have been confronted with Eclipse Juno ahead of schedule. I was not very lucky with the new default theme, which looks very ugly (on Ubuntu), so I decided to switch back to classic theme. Unfortunately there is some annoying issue. The active tabs are blue: [...]
Xubuntu 12.04 – How to set up wireless connection
After installing Xubuntu 12.04 on my pretty old laptop, my wireless network didn’t work. That means that # iwconfig didn’t even show me a wireless extension. First of all I had to get information about my wlan hardware chip:
|
1 |
# lspci -vvnn | grep 14e4 |
which showed me:
|
1 2 |
02:00.0 Ethernet controller [0200]: Broadcom Corporation NetLink BCM5787M Gigabit Ethernet PCI Express [14e4:1693] (rev 02) 04:00.0 Network controller [0280]: Broadcom Corporation BCM4311 802.11b/g WLAN [14e4:4311] (rev 01) |
..so I knew that it is supported: http://wireless.kernel.org/en/users/Drivers/b43#Supported_devices So b43 is [...]