Skip to content

Tag: java

Seeking in AES-CTR-encrypted input

As AES in CTR mode is great for random access, lets say I have a data source created with a CipherOutputStream in AES-CTR mode. The library underneath—which is not mine—uses a RandomAccessFile that allows to seek to a specific byte offset in the file. My initial thought would be to use a CipherInputStream wit…

Mockito mock objects returns null

I try to implement some tests for my JSF application and for the mocks I am using mockito. (I also use spring) The test succeeds, but when I want to retrieve the instance with the getInstance method. All Parameters which I have set before (via the constructor before) are null. I am new to mocked objects, so i…

Reading a log file which gets rolled over

I am trying to use a simple program to read from a log file. The code used is as follows: The code works well for new lines being added to the log file but it does not replicate the rollover process. i.e. when the content of the log file is cleared I expect the java console to continue reading text

Compare two XML strings ignoring element order

Suppose I have two xml strings How to write a test that compares those two strings and ignores the element order? I want the test to be as short as possible, no place for 10-line XML parsing etc. I’m looking for a simple assertion or something similar. I have this (which doesn’t work) Answer My or…

Loading a native library in an Android JUnit test

I’ve generated a native library using ndk-build which I’m able to load and use with in my Android application. However, I want to write some tests against this part of my app. When calling the native function in my tests, I recieve this exception message: …where process is my native library …

Java regex capturing groups indexes

I have the following line, I need to fetch the word ABC, I wrote the following code snippet, So if I put group(0) I get ABC: but if I put group(1) it is ABC, so I want to know What does this 0 and 1 mean? It will be better if anyone can explain me with good examples. The regex