Category: Java
-
Switching between multiple Java versions on OS X quickly
If you’re a Java developer like me, you will need to work on various Java versions. If so, adding the following in your ~./bash_profile makes switching between versions a snap. (As of this writing, I’m running on OS X El Capitan.) alias java6=’export JAVA_HOME=$(/usr/libexec/java_home -v 1.6);java -version’ alias java7=’export JAVA_HOME=$(/usr/libexec/java_home -v 1.7);java -version’ alias java8=’export…
-
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 mongoCollection = getMongoCollection(databaseName, collectionName); FindIterable 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): Java code (snipped): @ContextConfiguration(locations =…