Wednesday, March 14, 2018

Scala Mockito workarounds

I was pleased to have figured out this org.mockito.stubbing.Answer solution (lines 4-8) to a null logger inside my Scala class.

 Also, that you can tell a mock to call the real method you are trying to test (line 9).

 1  @Test
 2  def testNullHandlerCallsStart(): Unit = {
 3    predictor.setHandler(null)
 4    when(predictor.log == null).thenAnswer(new Answer[Logger] {
 5      def answer(invocation: InvocationOnMock): Logger = {
 6        LoggerFactory.getLogger("Predictor")
 7      }
 8    })
 9    when(predictor.enqueueEvent(any())).thenCallRealMethod()
10    val deactivation = new UnitUpdateNotification(unit, unit.updateStatus(Status.INACTIVE, Action.DEACTIVATED, "damaged", "user"))
11    callback.handle(deactivation)
12    verify(predictor).enqueueEvent(any(classOf[Event]))
13  }

One thing, I had to make the logger inside my Predictor class publicly visible for it to work.

Monday, July 24, 2017

Making a list from a single element

Super handy method from Google Collections

Sunday, April 30, 2017

How to scan with an HP C309a on Mac OS X Sierra

I have an HP c309a photosmart premium all in one print fax scan copy (never used for faxing) that is a very slow scanner but it's a scanner that does work so I'm not going to replace it if I can help it. Though today I gave that serious consideration when I discovered that with the new Mac OS, Sierra (10.12.4 at "press" time), the scanner is no longer supported even by HP Easy Scan.

When I tried running HP Easy Scan I got an error popup that said "Scanner reported an error: HP Photosmart C309a series is currently unavailable. Ensure your device is powered on, check the connection, and ensure your network is functioning properly. If these conditions are correct, restart the device and try scanning again."

I tried all these things, of course, with no luck. Searching on this found nothing but the strong suggestion that this product has passed its end of life and is no longer supported by HP. Argh HP why do you insist on being so lame.

I spent a while looking at replacements. I really don't want to spend a couple hundred bucks to replace this. My husband's printer doesn't work (begging the question why he keeps it) so I can't just get a new scanner.

Then I discovered that you can go into System Preferences, to Printers-Scanners, choose the Scanners tab, and scan through that! This worked for the first scan, on the flatbed, but then when I tried to use the automatic feeder, it did all the scanning and then displayed "No document loaded..." on the screen.

Sinking heart. Really need the ADF.

Suddenly it occurred to me that maybe it did work - I looked in the target directory - my files were there! "Scan.jpeg", "Scan 1.jpeg", "Scan 2.jpeg", etc. I can work with this!


p.s. It turns out I misunderstood what it meant by "No document loaded": There's nothing left in the feeder.

p.p.s. I have been using a great PDF splitter and merger software since it was a (I think open source) project in dev on Source Forge or similar. It's PDF Split And Merge and it is great. They've really improved the UI. I never upgraded from the old version I had until now, when I lost the old version in a computer upgrade. Highly recommend this app if you ever need to split or merge PDF files.

Thursday, February 16, 2017

Use correct header with CURL

Upon submitting a request to my service like

CURL -X POST http://localhost:8600/a/b/c -d '{"assignmentId[]":[12345]}'

I got this error:

"A servlet request, to the URI http://localhost:8600/a/b/c, contains form parameters in the request body but the request body has been consumed by the servlet or a servlet filter accessing the request parameters. Only resource methods using @FormParam will work as expected. Resource methods consuming the request body by other means will not work as expected."

Resolved with this answer from (thanks Arnold B.).

When I changed my request to

CURL -X POST http://localhost:8600/a/b/c -H "Content-Type: application/json" -d '{"assignmentId[]":[12345]}'

(adding the header) the service was able to parse the request and handle it normally.


Tuesday, April 5, 2016

Replacement for Windows Task Manager

Windows Sysinternals - a suite of sys admin tools (some require admin rights).


Process explorer - a much better replacement for Windows Task Manager - doesn't require admin rights and can help deetermine if a process has a lock on a DLL.

TCPView - shows all your port connections.

et al.

Monday, January 12, 2015

Selected differences in sed on mac and other *nix

A coworker sent me this sed command that works in other versions of unix command line:

sed -i "s/filename_prd/filename_dev/g" filename_dev.sql

But on Mac OS this what I had to do:

sed 's/filename_prd/filename_dev/g' ./filename_prd.sql > ./filename_dev.sql

Evidently the "-i" is not required in Mac, the command being sent to sed must be in single quotes and not double, and the output of sed goes to std_out so it needs to be saved to another file. (You can save it to the file itself but I prefer to be conservative about this.)