Thursday, February 16, 2012

Constants in Spring Context

Found an easy way to include a constant declared in some random Java file into the context file.

http://www.unicon.net/node/601

<bean id="Context" class="javax.naming.InitialContext"> 
    <constructor-arg> 
        <util:map id="jmsProperties" map-class="java.util.Hashtable"> 
            <entry> 
                <key><util:constant static-field="javax.naming.Context.INITIAL_CONTEXT_FACTORY"/></key> 
                <value>org.apache.activemq.jndi.ActiveMQInitialContextFactory</value> 
            </entry> 
            <entry> 
                <key><util:constant static-field="javax.naming.Context.PROVIDER_URL"/></key> 
                <value>tcp://localhost:61616</value> 
            </entry> 
        </util:map> 
    </constructor-arg> 
</bean>

Thursday, February 9, 2012

Installing the Aptana plugin in Eclipse makes Quick Diff colors unreadable

When I install this plugin my Quick Diff colors change, making it near impossible to read an SVN compare.

I have found that there are a couple potential fixes, or combinations thereof:

1. Go to Preferences -> General -> Editors -> Text Editors -> Quick Diff.
  • Changes ->  H:80 S:240 L:240 R:221 G:225 B:221
  • Additions ->  H:80 S:240 L:240 R:221 G:225 B:221
  • Deletions ->  H:0 S:240 L:232 R:255 G:238 B:238
2. Go to Aptana Studio -> Themes. Ensure Eclipse is chosen from the drop down box.

Thursday, January 19, 2012

Maven Test Dependency

With the maven-jar-plugin's goal test-jar, it is possible to create testing dependencies.

When doing this it is important to include the dependency twice, once normally (main code) and again with <type>test-jar<type>. So long as the dependency is built first, maven will find the test code.

Note: Eclipse doesn't seem to care which if both dependencies are there, causing some confusion, but when you go to run mvn from the cli, it will care.

http://maven.apache.org/guides/mini/guide-attached-tests.html

Thursday, October 20, 2011

EasyMock: Capture passed in values

I was writing a unit test this morning where the void method I was testing created an instance of a objected and passed it into a subsequent method. I needed to capture that object so that I could verify that it was set up properly. EasyMock provides a way to do this.

http://blog.jayway.com/2009/03/25/easymock-capturing-arguments-from-multiple-calls/

example:

Capture captured = new Captured();
expect(serviceInstance.method(EasyMock.capture(captured)).andReturn(/* whatever */);

MyObject obj = captured.getValue();

//run unit tests on obj

Friday, June 10, 2011

ResourceBundles and special characters

Seems that some special characters when used in a ResourceBundle proper file will throw off the parser for substitution. These characters need to be escaped properly, the escape notation is as follows:

The special chars \', { and }:

escape ' with another ' '' (double-single quote)
escape \ with another \
\\
(double backslash)
enclose } with '
'}'
enclose { with '
'{'

See also: