Thursday, March 31, 2011

Timezone

aptitude update tzdata
zdump -v America/Chicago | grep 2011

#epoch time 1970-01-01 00:00:00 UTC
date +%s

#epoch time of 12 Jan 2010 16:44:12 UTC
date -d "12 Jan 2010 16:44:12 UTC" +%s

#convert epoch time to readable date
date -d @371407800


//Windows
java -jar tzupdater.jar -f -bc -u

Tuesday, March 29, 2011

Java Mocking Operations

It is became common to use Mocking in java projrcts. But there are not so much examples from Mockito project. So Here is the examples how to do some test with Mockito.
Add maven dependency:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>

First you have to specify the following:

@RunWith(MockitoJUnitRunner.class)
public class YourTest

To mock any object you can use 2 approaches:

@Mock
private YourObject yourObject;

or

YourObject yourObject = mock(YourObject.class);

Verify operations example:
when(classField.getSpecificMethod()).thenReturn(stub value);
verify(classField).getSpecificMethod();
verifyNoMoreInteractions(classField);

verify(classField, atLeast(1)).getSpecificMethod();
*atLeast(1) can be replaced with: atLeastOnce(), never()

Exception generation:
YourException yourException = mock(YourException.class);
doThrow(yourException).when(classField).getSpecificMethod();
when(classField.getSpecificMethod(any(Class.class),anyInt())).thenThrow(new YourException ());

Thursday, March 24, 2011

SMB usage

smbclient '//computername/sharefolder' --workgroup=domainname --user=user
lcd /
put or get filename

Example: copy file to you windows machine

smbclient '//computername/sharefolder' --workgroup=domainname --user=user
lcd /path/to/file
put file.name

Friday, March 11, 2011

SSL keystore

By default keystore is users directory (example: C:\Users\myname\.keystore)

%JAVA_HOME%\bin>keytool.exe -importcert -file PATH_TO_CERT.cer –v
keytool.exe –list
%JAVA_HOME%\bin>keytool.exe -printcert - file PATH_TO_CERT.cer

Friday, March 4, 2011

Constructor chain execution with overriding methods inside

Note that when the Base constructor is called from within the Sub constructor, "this" clearly refers to an instance of Sub, not Base. Even though "this" has not been completely constructed yet, the JVM knows what class it will ultimately be. This is how it's able call overriding methods from the constructor.