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.

Tuesday, February 22, 2011

Ruby Cucumber BDD for Java devs

Nice article how to integrate cucumber into java project.
http://www.goodercode.com/wp/using-cucumber-tests-with-maven-and-java
Change cuke4duke version to 0.4.3 and picocotainer to 2.10.2
Happy BDD!

Friday, February 18, 2011

Ruby 1.9 configuration

http://ascarter.net/2011/01/02/rails-development-on-ubuntu-10.10.html

Thursday, February 10, 2011

SMTP (RFC822) testing

telnet mailhost port
EHLO
MAIL FROM: email
RCPT TO: email
DATA
Subject:
From:
To:
ENTER
message text
.