Monday, July 22, 2013

Mock private field and private method using PowerMock

Example 

public class PrivateObject {

    private String privateString;

    public PrivateObject(String privateString) {
this.privateString = privateString;
    }

    private String getPrivateString() {
return this.privateString;
    }

}


Mock using PowerMock

// class instance
PrivateObject instance = new PrivateObject ();

// mock private field/variable
MemberModifier
                .field(PrivateObject .class, "privateString").set(
instance , "hellomock");

// mock private method
MemberModifier
.stub(MemberMatcher.method(PrivateObject .class,
"getPrivateString"))
.toReturn(
"Power Mock");

Wednesday, June 12, 2013

Hot Swap featuring Maven and Maven Embedded web server 'Jetty'

Developer always want to utilize time fruitfully by doing new things instead of doing repeat kinds of work. In J2EE web application development, change made on view pages can be replicate instantly on browser by hard refresh but for instant result of change that made in java class, web server need to restart as it need to redeploy those changes made java classes after java compiler compile it.

So to escape from this, follow Hot Swap concept and implement it featuring Maven and Maven embedded web server Jetty.

maven, hot swap
     
${basedir} - root directory of project
In my implementation,
${maven-compiler.version} -   2.3.2
${java.source.version} - 1.6
${jetty.version} - 8.1.8.v20121106
${jetty.port} - 8080


Enjoy Hot-swap!!!!!!!!!!!

Eclipse IDE asking authentication credential for Subversion every time while updating and committing code.

To over come,
go to path
C:\Users\${user}\AppData\Roaming\Subversion\auth
and remove "svn.simple" folder.