JavaOne – Optional – the mother of all bikesheds

“Optional – the mother of all bikesheds”

Speaker: Stuart Marks
#OptionalBikeshed

The deck is available online

For more blog posts from JavaOne, see the table of contents


Showed early version of “optional” (stream returning null)

Review of basics

  • Two states – present (contains non null reference) or absent
  • Don’t say “null optional”. Say “absent” or “empty”
  • Optionals are immutable
  • equals() and hashCode() work as one would expect – useful for JUnit because can call assertEquals()

New in Java 9

  • stream() – stream with 0 or 1 elements
  • ifPresentOrElse(Consumer)
  • or(Supplier)

Good code and Best practices

  • Never set an Optional variable to null. It should be Optional.empty() as default.
  • If method returns Optional, never return a null either.
  • Intended for return types where might or might not have a value to return.
  • Don’t call get() as could be empty optional
  • Use isPresent() and get() as last resort
  • Using .map().orElse() chained after stream pipeline gives fluent API calls
  • Calling filter() returns original value only if non-empty optional that matches. else returns empty. Using filter() and orElseThrow() is good for validation
  • [and more see the deck]

My take: Amazed there is so much to say about Optional! Excellent set of best practices. And excellent point on not calling an optional “null.” I needed to leave early as my session is immediately after this one. And I really wanted to know “what’s with the bikeshed” which is covered last.  It’s a nice collection of quotes. So I found the deck and best practices online. There’s also a youtube video linked so you can watch at home.

JavaOne – Community Keynote

“Community Keynote”

For more blog posts from JavaOne, see the table of contents


IBM

  • This year, open sourced IBM JDK 9 (OpenJ9)and LIberty Server
  • Demo: microservices, error handling, live code update, Docker
  • Expecting coding in the cloud will become more common
  • More innovation needed: cloud dynamics, containers, hardware
  • Container Kindergarten – play will with others; don’t steal resources/toys from other containers
  • Competition around best JVM
  • Guarded storage – physical hardware that can run GC in parallel by adjusting to memory moves
  • “Server doesn’t even mean the same as it used to”
  • Java EE got reputation for being monolithic. Hasn’t been true in a long time. Now have lighweight runtimes Ex: TomEE, Liberty
  • Even with Kubernetes, need runtime so app can run in portable way
  • Open Liberty – supports Java EE 7, Microprofile, Docker. Uses Eclipse upgrade. Biggest open source contribution IBM ever made. Can get production support as paid upgrade. Designed to be run for microservices and cloud native apps.
  • Microprofie -optimized enterprise capabiities for micro services. Looking at contributing to Java EE or moving under EE4J umbrella.

Oracle

  • Cute skit about this being a rehersal for the Matrix. Callouts to Brazil and the Netherlands. Callout to Star Wars. Callout to Java’s new 6 month release schedule
  • [The lights are green which makes for an interesting reflection on my iPad keyboard]
  • Simulated [I think] tech failures
  • Used underscore variable and changed to double unerscore when didn’t compile
  • Counting: “8, 9 , 18.3, 18.9, whaaat”
  • Follow the white duke (to the JCP party
  • Scene 2: Juggie (a puppet), a bunch of JUG leaders in costumes and two artists
  • The blue J2EE bill taes you back and the red EE4J pill… YOur improvements will be faster now.
  • The agents are spreading fear saying Java EE is dead. The JUG Leaders are the first line of defense
  • Each JUG leader said something about upgrading or a new feature
  • RV carries more and has couch/bathroom. But motorcyce more agile an can go anywhere
  • Scene 3: green screen on motorcycle
  • Scene 4: Went to Japan to learn how to fight agents. Taught spirit of Jigsaw. Used the machine with the 60 Raspberry Pi devices in a circle to check punch. Creates video to see from all angles.
  • Scene 5: Virtual User Group – in 3 weeks, doing 24 hours of vjug. And a bunch of people from the vjug went up
  • Fun references to Java and EE from the matrix in the background as they did dialog
  • Matrix is killing processes as they start up. Deployed 6 instances of programming using Kubernetes to Google, IBM and Oracle clouds. Had visual as killed instances and they came back up. Scaled it 400 and watched the isul grow. Lots of references to the cost. . Google hangout session into VJUG
  • Scene 6: Meet architect of Matrix and our hero defeats the agents.. The agents make up and turn back into dev

My take: I was thinking of not going to the keynote to get some extra sleep and then getting ready for my session. Glad I woke up at 6:30 to get ready and attended to whole keynote. IBM’s was interestng and well put together. And Oracle’s “movie” was awesome! And the more people you recognized, the better it was. Lots of references to various news to such as Angular not having a migration path.

JavaOne – Java Test Automation for REST, Web and Mobile

“Java Test Automation for REST, Web and Mobile”

Speaker: Edson Yanaga & Elias Nogueira

Code had https://github.com/eliasnogueira/javaone-testing-automation

For more blog posts from JavaOne, see the table of contents


Toolbox for testing

  1. Test real REST Service – intermediate validation between back and front end
  2. Test mock REST service – so can guarantee stability during test cycles
  3. Test mobile UI – functional and acceptance tests
  4. Test Web UI – functional and acceptance tests

Test REST web service

  • Just as important as UI
  • Swagger – REST API documentation
  • Use curl or PostMan to manually validate before trying to automate. Postman provides a UI for running REST calls.

Mock REST web service

  • Spark – microframework for Java 8
  • Good discussion of why record/replay shouldn’t be the only tool for testers
  • Spark is a call to get (or the appropriate verb) method taking params for the URL and then a lambda for request/response logic
  • Rest Assured for testing – can integrate with Spark. Fluent API style

Test Web UI

  • Selenium for in browser testing.
  • Nobody in the room is using Selenium IDE. [good that everyone using it is on RC!]
  • Selenium uses a browser specific executable file
  • Workflow – Navigation, Integration (find a web element), Manipulation (click/update text), Synchronization (wait for dynamic elements/async request)
  • Chrome gives a warning that automated software opened the window [that’s awesome! you know it isn’t malicious if you did it and you know which isn’t your interactive session]

Test mobile UI

  • Appium uses same API/DSL as Selenium.
  • Can run Appium test on real device or emulator
  • Workflow – Desired Capabilities (ex: size), Session (start session), Interrogation/Manipulation, Synchronization

Best practices

  • Test against server, not just your machine
  • Use software to change the internet speed
  • Use page objects so test scripts are modular
  • Avoid XPATH
  • For mobile, have scripts for both fresh and pre-installed apps

My take: Good end to the day. It was nice to see a bunch of tools in a short time both on slides and with demos/live coding of each. The presenters were one tester and one developer creating a bunch of jokes back and forth.