Category: Java

  • How to install jshell via Homebrew

    At the time of this writing, Java 9 is in beta. I installed because I wanted to check out jshell, Java’s new REPL (read-evaluate-print-loop). On top of the below, I brew-installed jenv (a must for managing different JDK versions). $ brew install Caskroom/versions/java9-beta $ jenv add /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home $ jenv shell oracle64-9-ea $ java -version java…

  • Mongo DB: Iterate through a MongoCollection

    , ,

    This is specifically for Mongo 3.x, where MongoCollection is preferred over DBCollection. Adding for personal archiving. MongoCollection<Document> mongoCollection =             getMongoCollection(databaseName, collectionName);         FindIterable<Document> documents =             mongoCollection.find(eq(COLUMN, "lastName"))                 .sort(ascending("lastname"));         for (Document document : documents) {             …         }

  • Cucumber-JVM: Running a @Before step only for certain scenarios

    ,

    You can make use Cucumber’s @Before and @After to execute only for certain scenarios like the below. This is especially useful if you, say, wanted to make a (Mongo) DB connection for a few test scenarios. @Before("@mongo") public void beforeScenario() {   // actions } @After("@mongo") public void afterScenario() {   // actions } To complete the…

  • SpringBoot: Making use of @Value properties from YAML files for Cucumber tests

    In case you use: 1. SpringBoot to build your web applications using Java 2. Test it with Cucumber 3. Use YAML files for configurable property values You can use the YamlPropertiesFactoryBean to make use of @Value for your test configuration. application.yml: myapp:   base:     url: some_url cucumber.xml (or application context .xml): <context:component-scan base-package="cucumber.runtime.java.spring"/>     <context:annotation-config/>     <bean id="yamlProperties"…

  • IntelliJ IDEA: Plugin to generate SerialVersionUID

    ,

    Easy as pie. 1. Go to: File > Settings > Plugins > Browse repositories > GenerateSerialVersionUID. 2. Install the plugin and restart. 3. Generate the ID by: Code > Generate > serialVersionUID or the shortcut.

  • ActiveMQ error: “java.lang.RuntimeException: javax.jms.JMSException: Invalid version: 6, could not load org.apache.activemq.openwire.v6.MarshallerFactory”

    I was working on a project that needed to send JMS messages to an Apache ActiveMQ broker that was running an older version, specifically, 5.4.x. It started failing with the error below when I switched to it, but had no issues when it was connecting to another broker running 5.9.0. java.lang.RuntimeException: javax.jms.JMSException: Invalid version: 6,…