tag:blogger.com,1999:blog-127940492024-02-03T20:14:24.535+11:00The Wrath of Krangkrangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.comBlogger273125tag:blogger.com,1999:blog-12794049.post-5133093082347835452019-04-11T21:47:00.000+10:002019-04-11T21:48:07.389+10:00When the interview they told you to expect is not the interview that you get<div dir="auto"><div dir="auto">Alternate title:</div><div dir="auto">"What's worse than whiteboard coding? Surprise quiz whiteboard coding!"<br></div><div dir="auto"><br></div><div dir="auto"><div dir="auto" style="font-family:sans-serif">I had a bit of a shocker this morning. </div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Was told that the interview would be about past work experiences, system design, cases where I've demonstrated leadership skills. So I spent quite a bit of time going through projects in the past, reviewing issues, what I've done, design decisions, solutions, etc.</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">What did I get instead?</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Whiteboard coding. </div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Absolutely no word about this from HR. Was this what they meant by "technical interview"? Do a tricksy for-loop and lets see if you can find out the secret. Oooh, hahah. I get it.</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">IMO, whiteboard coding is basically the 21st century equivalent of 1990s Microsoft interview questions like "How would you move Mt Fuji?" </div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">(<a href="https://blog.codinghorror.com/the-hardest-interview-puzzle-question-ever/">https://blog.codinghorror.com/the-hardest-interview-puzzle-question-ever/</a>)</div><div dir="auto" style="font-family:sans-serif"> </div><div dir="auto" style="font-family:sans-serif">And c'mon. Are we in high school now?</div><div dir="auto" style="font-family:sans-serif">Surprise quiz! Prove you can code and deal with array indexes like a good boy.</div><div dir="auto" style="font-family:sans-serif">Every. Goddamn. Time.</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Now I didn't exactly set myself up for success, health wise. Mea culpa. Having only 5 hrs of sleep is not good. I was also throwing up this morning from either stress or just phlegm in my lungs. Maybe I have pneumonia? Oh boy, I should be so lucky.</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">Second problem was about removing adjacent duplicate characters pairs from a string. I got stuck on this way more than I should have. I first thought of doing it recursively but stuck to iterative approach instead. Used char arrays when I could've just used ArrayList. I wasn't at my best, tbh. I screwed up my health and turned into a two-legged stress ball. It should not have been that awful for me. I should have been in the zone. (Yes, excuses, excuses.)</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">I don't need to tell you that I would've done this pretty quickly in a couple of minutes given a computer. Even using *vi*. </div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">So we didn't get to the third part of the interview, the one that would've discussed the things I actually prepared for, about System Design and work.</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">I suppose I could've turned the tables and said "Hey, why don't we first do the question I actually prepared for, then we can do this crap you've just sprung on me without any notice?" At least my effort from last night wouldn't have been a total waste. Get a quick win, then do the nasty thing I hate doing. I probably should've been more assertive. Maybe I would have felt more settled after that. Perhaps. Perhaps. Perhaps.</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">I was at one point tempted to just go and leave. As if that would change or prove anything. </div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">But what did I need to prove, really? I already did the online coding test the week before. What does adding whiteboard coding do? Does it raise the bar? How?</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif">What are we trying to weed out at this stage of the process? People who hate being misled into preparing for something that was only 1/3 of the interview? The inferior, anxious types who don't like whiteboard coding? Programmers who are productive when using a computer? 😱</div><div dir="auto" style="font-family:sans-serif"><br></div><div dir="auto" style="font-family:sans-serif"><br></div></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-90856221203322187342017-03-01T02:52:00.000+11:002017-03-01T02:53:03.666+11:00"I know.. instead of typing a forward-slash in a string, I'll declare a static variable for the "/" character"<div dir="ltr"><div>Was looking at some code someone else wrote and came across:</div><div><br></div><div><font face="monospace, monospace">public static final String SLASH = "/ ";</font> </div><div><br></div><div>FML. Dude. WTF were you even thinking? Why even have a constant? To save us from typing? Instead of one character you now have 5, and then the "+" symbol. What are the odds of making an error on a forward slash? You're just using it in other static declarations anyway *in the same class*.</div><div><br></div><div><br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-47353658407819255372017-02-03T11:43:00.001+11:002017-02-03T11:43:49.584+11:00Java JPA and Generics and Type Erasure: Casting a List to List<div dir="ltr"><div>Java Generics are a bundle of compromises and workarounds. Backwards compatibility is a PITA. We all know that. Anyway... </div><div><br></div><div>I had a service class that, due to some refactoring, was now going to be returning a List<ParentClass> whereas before it could return a List<ChildClass>. We had some A/B testing inside the implementation, so in some cases, we would be actually returning a List<ChildClassTwo> from our DAO class.</div><div><br></div><div>My original fix for this was to create a new ArrayList and initialise it with the List of ChildClass or ChildClassTwo, but I didn't like the idea of having to create a new object just to change types.</div><div><br></div><div>But there's actually a better way, one that does not involve creating an extra wrapper object, that I found on StackOverflow.</div><div><br></div><div>To use the classic O-O hierarchy of Animal and Dog classes:</div><div><br></div><div>List<Dog> dogsInLocation = dao.findDogs(location);</div><br>List <Animal> animalsInLocation = (List<Animal>) (List) dogsInLocation;<br><div><br></div><div>So basically you are casting the List<Dog> "up" to a List, and then casting it "down" to a List<Animal></div><div><br></div><div>Trying to do </div><div><br></div><div> (List<Animal>) dogsInLocation;<br></div><div><br></div><div>gives you an "Inconvertible types" error. You can't directly go from a typed list of one type to a type of another. </div><div><br></div><div>The workaround is to use type erasure, turn it into a standard List, which gets rid of the type information about List<Dogs>, and *then* cast it to a List<Animal></div><div><br></div><div><br></div><div>REF: <a href="http://stackoverflow.com/a/663951/204255">http://stackoverflow.com/a/663951/204255</a><br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-51176783371013562502017-01-20T17:15:00.001+11:002017-01-20T17:15:41.256+11:00Rebuilding Nexus - what we did wrong and how we fixed it<div dir="ltr"><div><br></div>Nexus is just a searchable cache for all the various jars you either downloaded from the internet or generated from your code-base. <div><br></div><div>There are 2 main reasons you use a repository manager like Nexus or Artifactory:</div><div><br></div><div>* save on network requests, and make your builds faster</div><div>* predictability of builds, to serve as the 'source of truth' for all your release artifacts</div><div><br></div><div><br></div><div>Now we had a recent problem with Nexus. It got totally f*cked. I'm not privy to all the gory details, but we seem to have lost a few files.</div><div><br></div><div>This shouldn't be that big a deal, because we could just reconstruct Nexus from the files we already have in our Maven /.m2 directories -- we could take a new Nexus instance and populate it with the files we have. </div><div><br></div><div>However, during the process we made a couple of errors, and it took us a few days as we discovered the problems day by day, depending on what projects we were rebuilding and what errors we were getting.</div><div><br></div><div><div>Now Nexus seems to have changed the way it works, and was no longer a system that could just be pointed to a file system to do a mass import. It looked like there wasn't actually any way to do bulk imports of an existing file system repository. So we had to do the import by individual files.</div></div><div><br></div><div>Most of the contents of Nexus were jars that came from either the main Maven repository, or other repos like Apache, Spring or Atlassian, so getting those wasn't an issue.</div><div><br></div><div>The main thing we had to repopulate were internal jars that we'd released and uploaded into Maven. One of the sysadmins wrote a script to recurse through internal jars from the /.m2/repository/ directory on our build server and then upload them into Nexus. However there were some bugs in the script, that resulted in people getting broken repositories.</div><div><br></div><div>The things we did wrong were:</div><div><br></div><div>1. Uploading jars into Nexus without specifying the pom file. By default, Nexus created a default pom file, but this only contained basic information like groupId, artifactId and version. No dependencies. </div><div><br></div><div>Result: Transitive dependencies couldn't get resolved during builds in Maven, so compilation broke.</div><div><br></div><div>How We Found The Issue: Looking at the artifact directory in our local repo, and looking at the POM file. </div><div><br></div><div>Fix: Update the command to deploy the file to specify both the Jar and Pom file.</div><div><br></div><div><br></div><div>2. Assuming that a .jar file was a java Jar. This was incorrect, because maven builds can also produce JAR containing source or javadoc. This resulted in the source or javadoc jar being mistakenly uploaded. </div><div><br></div><div>Result: Builds broke because class files couldn't be found.</div><div><br></div><div>How We Found The Issue: Looking at the .jar file in local repo, opening it, and inspecting contents. No .class files - wrong jar upload</div><div><br></div><div>Fix: Update the command to exclude *-source.jar and *-javadoc.jar from deploys.</div><div><br></div><div><br></div><div><br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-21575443849305471862016-08-25T11:39:00.001+10:002016-08-25T11:39:57.103+10:00Unit tests with mockito - how to verify that a parameter to a mock method call has an expected value<div dir="ltr"><br><div><a href="http://stackoverflow.com/questions/1142837/verify-object-attribute-value-with-mockito">http://stackoverflow.com/questions/1142837/verify-object-attribute-value-with-mockito</a><br></div><div><br></div><div>Use ArgumentCaptor, then in your verify() call for the method call you're setting up, use the argumentCaptor instead of the usual .class you'll be passing.</div><div><br></div><div>Then in your assert() to check the value, see if the argumentCaptor.getValue().get<field> has the value you're expecting</div><div><br></div><div>Basic idea is that you use ArgumentCaptor as the proxy to intercept the value the mock is getting.</div><div><br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-52735203872142152732016-01-27T10:32:00.000+11:002016-01-27T10:33:29.432+11:00JSTL transforms null BigDecimal to 0 and null String to ""<div dir="ltr"><br><div>Was scratching my head why I was getting zero for a BigDecimal that I was returning as null, then realised I'd forgotten about JSTL behaviour that cleans up nulls to nicer values.</div><div><br></div><div>So anything extending type Numeric that is null gets shown as 0.</div><div><br></div><div>And anything that is a null String becomes a blank String.</div><div><br></div><div><br></div><div><br></div><div><font color="#000000" face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:14.85px;line-height:20.79px">As mentioned here:</span></font></div><div><font color="#000000" face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:14.85px;line-height:20.79px"><br></span></font></div><div><p style="color:rgb(0,0,0);font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:14.85px;line-height:20.79px">After a bit of trial and error I discovered that the JSP tab library framework does a little bit of magic on known classes, such as <code>String</code>s and <code>Numeric</code>objects. Classes of <code>Numeric</code> types that are <code>null</code> get converted to <code>0</code> and<code>String</code>s get converted into the empty string <code>""</code><br></p><p style="color:rgb(0,0,0);font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:14.85px;line-height:20.79px">I discovered that if you change your internal value to an<code>java.lang.Object</code> instead of a <code>java.math.BigDecimal</code> the magic doesn't know what to do and just passes <code>null</code> to your class.</p><p style=""><font color="#000000" face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:14.85px;line-height:20.79px">Reference: </span></font></p><p style=""><font color="#000000" face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:14.85px;line-height:20.79px"><a href="http://andykayley.blogspot.com.au/2011/09/how-to-pass-null-value-to-custom-tag.html">http://andykayley.blogspot.com.au/2011/09/how-to-pass-null-value-to-custom-tag.html</a></span></font><br></p><p style=""><font color="#000000" face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:14.85px;line-height:20.79px"><br></span></font></p><p style=""><font color="#000000" face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:14.85px;line-height:20.79px"><br></span></font></p></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-67160273794072596092015-12-11T10:38:00.000+11:002015-12-11T10:39:04.830+11:00Problem and solution: "Content not allowed in prolog" when loading XML as string, even without extra characters<div dir="ltr"><div>I was parsing XML files in a unit test, but was doing it incorrectly.</div><div><br></div><div>I was loading them from classpath, then wanted to have them in a string and compare them using XMLUnit.</div><div><br></div><div><br></div><div>WRONG WAY</div><div><br></div><div><div>InputStream devStream = getClass().getClassLoader().getResourceAsStream("api-response--dev.xml");</div><div><br></div><div>String devXml = devStream.toString();</div></div><div><br></div><div><br></div><div>I was getting "Content not allowed in prolog" when I tried to parse this as XML, even though there was no BOM or extra characters in the source XML file.</div><div><br></div><div>Turns out I was doing it incorrectly. Because if you call toString(), you end up using the default encoding of your platform. </div><div><br></div><div><br></div><div>RIGHT WAY</div><div><br></div><div><br></div><div>InputStream devStream = getClass().getClassLoader().getResourceAsStream("api-response--dev.xml");</div><div><br></div><div>String devXml = CharStreams.toString(new InputStreamReader(devStream, "UTF-8"));</div><div><br></div><div><br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-76145379734231813262015-11-19T16:00:00.001+11:002015-11-19T16:00:56.762+11:00How to fix "Unlink of file '.git/objects/pack/pack-(longhash)' failed. Should I try again? (y/n)<div dir="ltr"><div>possible tags: Git GC, git cleanup repository, </div><div><br></div>Every now and then while using Git, like say when you do a "git pull" on a repository which regularly gets a lot of changes, you will get a message from Git like this:<div><br></div><div><div>Auto packing the repository for optimum performance. You may also</div><div>run "git gc" manually. See "git help gc" for more information.</div><div>Counting objects: 499419, done.</div><div>Delta compression using up to 24 threads.</div><div>Compressing objects: 100% (164548/164548), done.</div><div>Writing objects: 100% (499419/499419), done.</div><div>Total 499419 (delta 238160), reused 493660 (delta 233258)</div><div><br></div><div>And then you might see this:</div><div><br></div><div><div>Unlink of file '.git/objects/pack/pack-061698b76ddcbea46c9d31874b73c9a66d87f790.pack' failed. Should I try again? (y/n)</div><div>n</div><div>Unlink of file '.git/objects/pack/pack-061698b76ddcbea46c9d31874b73c9a66d87f790.idx' failed. Should I try again? (y/n)</div><div><br></div><div>You'll find that if you press "n", you'll find yourself pressing "n" a *lot* of times... this is pretty much the point where you should just go:</div><div><br></div><div>Ctrl-C </div><div><br></div><div>and then just do a </div><div><br></div><div>$ git gc</div></div><div><br></div><div>to manually pack your repository.</div></div><div><br></div><div><div>$ git gc</div><div>Counting objects: 499419, done.</div><div>Delta compression using up to 24 threads.</div><div>Compressing objects: 100% (159646/159646), done.</div><div>Writing objects: 100% (499419/499419), done.</div><div>Total 499419 (delta 238160), reused 499419 (delta 238160)</div><div>Removing duplicate objects: 100% (256/256), done.</div><div>Checking connectivity: 499419, done.</div></div><div><br></div><div><br></div><div>Done!</div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-87785776255605649172015-08-27T15:48:00.000+10:002015-10-12T13:03:07.597+11:00If there's an error, isn't it better to fail and show the error? <div dir="ltr">
<br />
<div>
<div>
# if we didn't have a placeholder, we wouldn't have to escape the single quote</div>
<div>
# but if we have a placeholder, then we have to escape the single quote</div>
<div>
# otherwise: single quote doesnt show AND placeholder doesnt receive our parameter!</div>
<div>
<br /></div>
<div>
mail.body.donate=Hi there, I'd like to donate ${0}</div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
I was using Spring's MessageResource to load this value from a properties file, passing in a single item array with the value I wanted to show after the word "donate"</div>
<div>
<br /></div>
<div>
But for some reason, it kept showing only this:</div>
<div>
<br /></div>
<div>
Hi there, Id like to donate ${0}</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
I've had this problem for too days, and then eventually I removed this and replaced it with a message that only had letters and spaces, aside from the placeholder</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<div>
Hi there I would like to donate ${0}</div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
And it replaced it with:</div>
<div>
<br /></div>
<div>
<div>
<div>
Hi there I would like to donate $300</div>
</div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
So it looked like it was either the "," or "'" (single quote) that was the problem.</div>
<div>
<br /></div>
<div>
Eventually, I found this page:</div>
<div>
<br /></div>
<div>
<a href="http://www.mscharhag.com/java/resource-bundle-single-quote-escaping">http://www.mscharhag.com/java/resource-bundle-single-quote-escaping</a></div>
<div>
<br /></div>
<div>
This part had the answer:</div>
<div>
<br /></div>
<div>
<div style="color: #333333; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; line-height: 20px; margin: 0px 0px 10px;">
Java code:</div>
<div style="color: #333333; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; line-height: 20px;">
<div class="" id="highlighter_237016" style="font-size: 1em!important; margin: 1em 0px!important; overflow: auto!important; width: 823.5px;">
<table border="0" cellpadding="0" cellspacing="0" style="background: none!important; border-collapse: collapse; border-radius: 0px!important; border-spacing: 0px; border: 0px!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: 806px;"><tbody style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">
<tr style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;"><td class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: rgb(175,175,175)!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;"><div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
1</div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
2</div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
3</div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
4</div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
5</div>
</td><td class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-family: 'Courier New',Courier,monospace; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: 774px;"><div class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: rgb(0,102,153)!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; font-weight: bold!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">private</code> <code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: rgb(0,102,153)!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; font-weight: bold!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">void</code> <code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">printMessage(String code, Object... args) {</code></div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: #c7254e; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;"> </code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">Locale locale = </code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: rgb(0,102,153)!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; font-weight: bold!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">new</code> <code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">Locale(</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: blue!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">"en"</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">);</code></div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: #c7254e; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;"> </code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">String message = messageSource.getMessage(code, args, locale);</code></div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: #c7254e; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;"> </code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">System.out.println(message);</code></div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">}</code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="color: #333333; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; line-height: 20px;">
<div class="" id="highlighter_393532" style="font-size: 1em!important; margin: 1em 0px!important; overflow: auto!important; width: 823.5px;">
<table border="0" cellpadding="0" cellspacing="0" style="background: none!important; border-collapse: collapse; border-radius: 0px!important; border-spacing: 0px; border: 0px!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: 806px;"><tbody style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">
<tr style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;"><td class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: rgb(175,175,175)!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;"><div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
1</div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
2</div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
3</div>
</td><td class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-family: 'Courier New',Courier,monospace; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: 774px;"><div class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">printMessage(</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: blue!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">"test.message1"</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">);</code></div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">printMessage(</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: blue!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">"test.message2"</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">, </code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: blue!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">"John"</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">);</code></div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">printMessage(</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: blue!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">"test.message3"</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">, </code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: blue!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">"message"</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">);</code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="color: #333333; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; line-height: 20px; margin: 0px 0px 10px;">
Output:</div>
<div style="color: #333333; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; line-height: 20px;">
<div class="" id="highlighter_305995" style="font-size: 1em!important; margin: 1em 0px!important; overflow: auto!important; width: 823.5px;">
<table border="0" cellpadding="0" cellspacing="0" style="background: none!important; border-collapse: collapse; border-radius: 0px!important; border-spacing: 0px; border: 0px!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: 806px;"><tbody style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">
<tr style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;"><td class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: rgb(175,175,175)!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;"><div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
1</div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
2</div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-bottom-color: rgb(204,204,204); border-left-color: rgb(204,204,204); border-radius: 0px!important; border-right-color: rgb(108,226,108)!important; border-right-style: solid!important; border-top-color: rgb(204,204,204); border-width: 0px 3px 0px 0px!important; float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 0.5em 0px 1em!important; text-align: right!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
3</div>
</td><td class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-family: 'Courier New',Courier,monospace; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: 774px;"><div class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">John's message</code></div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">Johns message</code></div>
<div class="" style="background-image: none!important; background-repeat: initial!important; border-radius: 0px!important; border: 0px rgb(204,204,204); float: none!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin-bottom: 40px; margin-left: 0px!important; margin-right: 0px!important; margin-top: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px 1em!important; vertical-align: baseline!important; white-space: pre!important; width: auto!important;">
<code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">Johns {</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: rgb(0,153,0)!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">0</code><code class="" style="background: none!important; border-radius: 0px!important; border: 0px!important; color: black!important; float: none!important; font-family: Consolas,'Bitstream Vera Sans Mono','Courier New',Courier,monospace!important; font-size: 1em!important; height: auto!important; line-height: 1.1em!important; margin: 0px!important; min-height: auto!important; outline: 0px!important; overflow: visible!important; padding: 0px!important; vertical-align: baseline!important; width: auto!important;">}</code></div>
</div>
</td></tr>
</tbody></table>
</div>
</div>
<div style="color: #333333; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; line-height: 20px; margin: 0px 0px 10px;">
The first message does not take any arguments, so no <span style="font-family: 'Courier New',Courier,monospace;">MessageFormat</span> is applied and the single quote does not need to be escaped. The second and third messages, however, are formatted by a <span style="font-family: 'Courier New',Courier,monospace;">MesssageFormat</span> which processes the single quote characters. In these messages the single quotes should better be escaped with another single quote character otherwise they won't show up in the output.</div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
I'm not a fan of this "fail, but partly work". I'd rather have complete failure with a clear indication of where things failed, rather than partially working, but no indication of why things are failing.</div>
<div>
<br /></div>
<div>
<br /></div>
</div>
krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-16375644061244325292015-08-06T12:39:00.001+10:002015-08-06T12:39:50.795+10:00When a deployment doesn't work, and logs don't show anything: Restart it! (AKA It was working on the other QA box!)<div dir="ltr"><div>PROBLEM:</div><div><br></div><div>We have a number of QA (Quality Assurance, ie, testing) boxes. Release candidates (RC) go on a specific QA box, one that is more prod-like. The problem was an application that was working on the other QA boxes but not on the RC QA box.</div><div><br></div><div><br></div><div>We tailed the log files while testing the functionality - no errors.</div><div> </div><div>We had a look at the libraries that were deployed. They were as expected.</div><div><br></div><div>We manually made calls to the service endpoints using curl - we were getting a 404! </div><div><br></div><div>Okay, now what's going on?</div><div><br></div><div>Was it a mistake in the jar we released - in the past we've had some code not getting merged into master during release. Opened the jar - yup, contents were there.</div><div><br></div><div>Was it a mistake in the URL? Nope. It works on the other QA box.</div><div><br></div><div>Now doing a "ps" would usually show the libraries being loaded on the classpath, but this app was different and didn't actually do that. </div><div><br></div><div>Could it be that the *old* version was still running? We had no quick way of knowing this. But the fact that the webapp didn't know this new endpoint even though we had the new jar file in the filesystem was pointing to this.</div><div><br></div><div>So we restarted the process. That fixed it! Functionality all working either through direct calls via curl or the webapp.</div><div><br></div><div><br></div><div>LESSON:</div><div><br></div>When investigating something that should already be working, the steps should be: <div><br></div><div>1) Check the logs. </div><div>2) Check that it's actually deployed </div><div>3) If 1 or 2 don't show anything wrong, restart the application. <br></div><div><div><br></div></div><div>Saves so much time.</div><div><br></div><div>The culprit was a Jenkins job that deployed the package but didn't successfully kill the old process. </div><div><br></div><div><br></div><div>How do we check that the process is running the new code? Our plan is to have an endpoint that can be queried to show release information - so we know the libraries in use by the application currently running. Our Jenkins job should then check this URL after it's deployed the package, and send out an alert if it's not getting the expected results.</div><div><br></div><div>4) Have an endpoint showing the state of the running process, library versions and configuration</div><div>5) Get Jenkins to check the release info endpoint after it deploys a package</div><div><br></div><div><br></div><div><br></div><div> </div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-25064397946580475592015-07-31T14:52:00.001+10:002015-07-31T14:52:51.011+10:00Reading in a file when directory names have spaces in them<div dir="ltr"><div>PROBLEM:</div><div><br></div><div>We were running some errors in our Jenkins build of some code, even though the code works on our computers. </div><div><br></div><div><pre style="white-space:pre-wrap;word-wrap:break-word;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);font-size:13px">java.io.FileNotFoundException: File '/var/lib/jenkins/workspace/Email%20Project%20Release/target/test-classes/com/company/mailFolder/sample_email.txt' does not exist</pre><pre style="white-space:pre-wrap;word-wrap:break-word;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);font-size:13px"><br></pre><pre style="white-space:pre-wrap;word-wrap:break-word;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);font-size:13px">I ssh'd to the Jenkins box and tried to ls on the directory name:</pre><pre style="white-space:pre-wrap;word-wrap:break-word;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);font-size:13px"><br></pre><pre style="white-space:pre-wrap;word-wrap:break-word;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);font-size:13px">and I got</pre><pre style="white-space:pre-wrap;word-wrap:break-word;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);font-size:13px"><br></pre><pre style="word-wrap:break-word;margin-top:0px;margin-bottom:0px"><font color="#333333"><span style="font-size:13px;white-space:pre-wrap">ls: cannot access <br></span></font><span style="color:rgb(51,51,51);font-size:13px;white-space:pre-wrap;font-family:arial,sans-serif">/var/lib/jenkins/workspace/Email%20Project%20Release/target/test-classes/com/company/mailFolder/sample_email.txt</span><span style="font-size:13px;white-space:pre-wrap;color:rgb(51,51,51);font-family:arial,sans-serif">: No such file or directory</span></pre><pre style="white-space:pre-wrap;word-wrap:break-word;margin-top:0px;margin-bottom:0px;color:rgb(51,51,51);font-size:13px"><br></pre></div><div>Then I realised it was the '%20' -- it was trying to load a url encoded directory name..</div><div><br></div><div>Doing an ls this directory worked:</div><div><br></div><div>ls -l "<span style="color:rgb(51,51,51);font-size:13px;white-space:pre-wrap">/var/lib/jenkins/workspace/Email Project Release/target/test-classes/com/company/mailFolder/sample_email.txt'</span></div><div><br></div><div>I looked in the code and it was doing this:</div><div><br></div><div><div>File mailFolder = new File(getClass().getResource("mailFolder"));</div><div>File mailFile = new File(mailFolder, "sample_email.txt");<br></div></div><div><br></div><div>I tested doing the first line with a folder that had spaces in it and I found it would return a path with any spaces replaced by '%20'</div><div><br></div><div><br></div><div>SOLUTION:</div><div><br></div><div>From stackoverflow, I found that the best way to get the correct folder reference was to do this</div><br><div><div>File mailFolder = FileUtils.toFile(getClass().getResource("mailFolder"));<br></div></div><div>File mailFile = new File(mailFolder, "sample_email.txt");<br></div><div><br></div><div>At first, I tried to load the file directly and it only returned null. Getting the File reference to the folder first, then creating the reference to the file is the only way that works, despite what the Stackoverflow article said (REF).</div><div><br></div><div><br></div><div><br></div><div>REF:</div><div><br></div><div><a href="http://stackoverflow.com/questions/10536183/resource-files-not-found-from-junit-test-cases">http://stackoverflow.com/questions/10536183/resource-files-not-found-from-junit-test-cases</a><br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-89284948903664546452015-07-01T14:25:00.000+10:002015-07-01T14:26:07.239+10:00Move module in git repo to its own repository but retain history<div dir="ltr"><br><div><a href="http://ariya.ofilabs.com/2014/07/extracting-parts-of-git-repository-and-keeping-the-history.html">http://ariya.ofilabs.com/2014/07/extracting-parts-of-git-repository-and-keeping-the-history.html</a><br></div><div><br></div><div>This is so much better than having the history of all files start from scratch.</div><div><br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-46643994313717135682015-02-23T00:31:00.001+11:002015-02-23T00:31:48.080+11:00My favourite moment in "Halt and Catch Fire"<div dir="ltr"><div><br></div><div>S01E09, at around 22:45</div><div><br></div><div>Gordon: "... You hit an overhang, and you can't climb up, and it's too steep to climb down. You realise what the word "jump" really means. And if I held your hand and counted to three.. I wasn't sure you'd come with me."</div><div><br></div><div>Donna: "We're married, Gordon. We already jumped."</div><div><br></div><div><br></div><div>That line just hit me. Hard.<br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-44050317138776404812014-10-30T23:03:00.000+11:002014-10-30T23:04:32.317+11:00WTF Cnet? Put HREF attributes in those anchor tags! A link tag without a link is pretty stupid.<div dir="ltr"><br><div><div>When is a an <a> anchor tag not really an anchor tag... when it doesn't have a href attribute. </div><div><br></div><div>WTF Cnet. </div><div><br></div><div><br></div><div>I was reading this article on Cnet and I started going through the list on the right of the page - "This Week's Must Reads" (see image)</div><div><br></div><div><br></div></div><div><br></div><div><a href="http://3.bp.blogspot.com/-WgcFaCuod4c/VFIpUNcm4JI/AAAAAAAAAXE/GwaM-tTctU8/s1600/Screen%2BShot%2B2014-10-30%2Bat%2B10.53.27%2Bpm-772318.png"><img src="http://3.bp.blogspot.com/-WgcFaCuod4c/VFIpUNcm4JI/AAAAAAAAAXE/GwaM-tTctU8/s320/Screen%2BShot%2B2014-10-30%2Bat%2B10.53.27%2Bpm-772318.png" border="0" alt="" id="BLOGGER_PHOTO_ID_6075964274459992210" /></a></div><div><div><div>Now normally, when I want to read articles, I open them in separate tabs so I can look at them after I finish the current tab. Now in this case the "Open In New Tab" option wasn't opening up in Chrome. So I call on "Inspect Element" option and I get this:</div><div><br></div><div><a class="title" data-goto="5657a735-cbf6-40b4-8453-94cb94630900" data-url="/news/for-gorilla-glass-testers-life-is-a-daily-grind-and-scratch-and-drop/" data-s-object-id="TOC.2"></div><div><br></div><div> <div class="col-1"></div><div> <div class="progress">2</div></div><div> </div></div><div><br></div><div> <div class="col-3"></div><div> <div class="hed">For Gorilla Glass testers, life is a daily grind (and scratch and drop...)</div></div><div><br></div><div> <span class="topic">Phones</span></div><div> </div></div><div> </a></div></div><div><br></div><div><br></div><div>The link probably only works after a click event. But what's the purpose of this? </div><div><br></div><div>Now admittedly, I've been guilty of doing something similar last year, for SEO purposes. There were links on the website of my company that they wanted to de-prioritise as they wanted the main content links getting crawled first. So I did exactly the same technique - put the URL in a data attribute. I event reversed it, so that crawlers woudln't recognise the attribute as a URL and try to crawl it. But the links I did that on were only links to FAQ and generic help. People wouldn't normally go to them anyway. But this.. </div><div><br></div><div>A list of most read articles on a news site is arguably on the same level of importance as the main article, as it leads people to consume more content on the site. So why would they make things a little more difficult for us tab-users by removing the href attribute?</div><div><br></div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-4075811568824395572014-09-24T11:51:00.000+10:002014-09-24T11:52:15.955+10:00PuTTY default colours suck, so replace it with a better colour scheme like zenburn<div dir="ltr"><div>PuTTY defaults to horrible combinations like using black background, with blue text for directories. WTH, after all these years?</div><div><br></div><div>Replace that with a better colour scheme. I came across Zenburn for PuTTY.</div><div><br></div><br><div>Step 1:</div><div><br></div><div>Go to</div><div><br></div><div><a href="https://github.com/voieducode/putty-colors-zenburn/blob/master/zenburn-putty.reg">https://github.com/voieducode/putty-colors-zenburn/blob/master/zenburn-putty.reg</a><br></div><div><br></div><div>Step 2:</div><div><br></div><div>Save this as a .reg file. Make sure you're saving the content, and not ending up with the HTML of the github page.</div><div><br></div><div>Step 3:</div><div><br></div><div>Right click, and then select "Merge"</div><div><br></div><div>You'll know if it worked as you'll get a message</div><div><br></div><div>In PuTTY, a "Zenburn" session will be created. This has your new, better colours.</div><div><br></div><div>Step 4: (do this for all your existing entries)</div><div><br></div><div>NOTE: this assumes that </div><div>a. your session only has the hostname as its contents, because that's all you'll be copying.</div><div>b. your hostname is the same as your putty session name</div><div><br></div><div>Load the existing entry you want to change.</div><div>Copy the hostname to clipboard</div><div>Load the Zenburn session.</div><div>Paste the hostname into the session name</div><div>Paste the hostname into the host details</div><div>Click on Save</div><div><br></div><div>Test it by opening this session. Colours shoud be better now.</div><div><br></div><div>Repeat for all your PuTTY session entries.</div><div><br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-66394813219006249222014-09-23T16:40:00.000+10:002014-09-23T16:41:31.018+10:00Given a list of values, recursively go through subdirectories and find the matching files of a specific filename<div dir="ltr"><div>Unix grep example:</div><div><br></div>fgrep -R -f sorted_untrusted_values_to_find.txt --include=".thisfile"<br><div><br></div><div>1. Given a list of values, contained in the file "sorted_unstrusted_values_to_find.txt", where each row has one value</div><div><br></div><div>-f sorted_untrusted_values_to_find.txt <br></div><div><br></div><div>2. recursively traverse the subdirectories under our current location</div><div><br></div><div> -R <br></div><div><br></div><div>3. looking at the files named ".thisfile"</div><div><br></div><div>--include=".thisfile"<br></div><div><br></div><div>3. return the files that have a match</div><div><br></div><div><br></div><div><br></div></div> krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-87120705269520954142014-07-30T17:45:00.000+10:002014-07-31T10:07:13.332+10:00Moving your Git working directory from Linux to Windows? There are two issues that you're probably going to getThe simpler solution would be to just check out the repository, but in
<br />
some cases you probably have some branches and stashes in your local
<br />
repository that you don't want to lose. So if you want to keep your
<br />
current local repo, you'll definitely have to deal with these two
<br />
issues. Here's how to solve them.
<br />
<br />
A. The line endings issue. You want to make sure that you're not
<br />
inadvertently checking in CRLF line endings.
<br />
<br />
Make sure you set this:
<br />
<br />
git config --global core.autocrlf true
<br />
<br />
This tells Git to use the system's default line ending (CRLF) when
<br />
checking out and LF when checking in.
<br />
<br />
B. File permissions being changed by Cygwin
<br />
<br />
The executable bit on Git repository files will get changed, and you
<br />
will have permissions "changes" in your git respository immediately
<br />
after checkout. Fix this by turning git's core.filemode config to
<br />
false. Refer to this post:
<br />
<a href="https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-dev/0EdNev3NNsw">https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-dev/0EdNev3NNsw</a>
<br />
<br />
1. Turn it for globally: git config --global core.filemode false
<br />
2. Turn it off for each repo: git config core.filemode false
<br />
3. Turn it off for all the submodules of each repo: git submodule
<br />
foreach --recursive git config core.filemode false<br />
<br />
If you don't change do (B), then when you do 'git status' you'll find it listing a lot of files that have been changed. Then when you do a 'git diff' on one of them, you'll see that the only change was in the executable bit in the permissions, ie<br />
<br />
$ git diff scripts/e2e-test.sh<br />
diff --git a/scripts/e2e-test.sh b/scripts/e2e-test.sh<br />
old mode 100755<br />
new mode 100644<br />
<br />
<br />krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-17001859772610893102014-04-01T16:54:00.001+11:002014-04-01T17:02:27.863+11:00Mockito - don't use @InjectMocks if your constructor will be calling methods on your injected mocksI had this:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@Mock</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">MessageSource mockMessageSource;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@InjectMocks</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">PhoneNumberUtil phoneNumberUtil;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@Before</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">public void setup() {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> MockitoAnnotations.initMocks(this);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> when(mockMessageSource.getMessage(eq("first.key"), (Object[]) eq(null), anyString(),eq(Locale.getDefault()))).thenReturn("This is a default message");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> when(mockMessageSource.getMessage(eq("second.key"), (Object[]) eq(null), anyString(),eq(Locale.getDefault()))).thenReturn("second Value");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<br />
<br />
Where<br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">public PhoneNumberUtil(MessageSource messageSource) {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> this.firstValue = messageSource.getMessage("first.key"), null, FIRST_DEFAULT_VALUE, Locale.getDefault());</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> this.secondValue = messageSource.getMessage("second.key"), null, SECOND_DEFAULT_VALUE, Locale.getDefault());</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<br />
<br />
<br />
I was running my unit test but wondering why the fields "firstValue" and "secondValue" were still coming out as null.<br />
<br />
I already mocked the messageSource.getMessage() calls. Why weren't my mocks getting called??<br />
<br />
Then I realised: the when().thenReturn() calls weren't getting called until AFTER PhoneNumberUtil was already initialized!<br />
<br />
<br />
I was using @InjectMocks and once the line<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">MockitoAnnotations.initMocks(this);</span><br />
<br />
was called, phoneNumberUtil would already get initialised with mockMessageSource. But at that point, mockMessageSource isn't setup to do anything yet.<br />
<br />
So the fix was to do this in my setup()<br />
<br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@Mock</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">MessageSource mockMessageSource;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">PhoneNumberUtil phoneNumberUtil;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">@Before</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">public void setup() {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> MockitoAnnotations.initMocks(this);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> when(mockMessageSource.getMessage(eq("first.key"), (Object[]) eq(null), anyString(),eq(Locale.getDefault()))).thenReturn("This is a default message");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> when(mockMessageSource.getMessage(eq("second.key"), (Object[]) eq(null), anyString(),eq(Locale.getDefault()))).thenReturn("second Value");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> phoneNumberUtil = new PhoneNumberUtil(mockMessageSource);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<br />
<br />
If you need to make a call on a mocked dependency in the constructor of the class you're testing, then you can't use the @InjectMocks pattern.<br />
<br />
You need to create the class you are testing using code, not annotations, using constructor injection to pass in the mocked dependencies, and you need to create it after you've mocked the methods being called in the constructor.<br />
<br />
<br />krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-55066569521811191702014-03-14T14:32:00.001+11:002014-03-14T14:32:48.028+11:00Prevent Googlebot from crawling some links, but still have them useable by the userWHAT:
<br>
<br>Prevent Googlebot from crawling some links, so that other more
<br>important links on our page are given priority and indexed faster
<br>
<br>
<br>HOW:
<br>
<br>1. remove the link, replace with "#" so it's still a valid HREF
<br>2. Put the value as data attribute, ie, data-goto
<br>3. Reverse the value because if we had data-goto="/productlist.html",
<br>Googlebot would still crawl it.
<br>Instead we have data-goto="lmth.tsiltcudorp/"
<br>4. On loading the page, run a javascript to go through all the links
<br>that have this attribute, reverse the string and place it in the
<br>"href" attribute. Googlebot can't run javascript so it never sees the
<br>HREF values in there.
<br>
<br>RETURNED BY SERVER
<br>
<br><a class="unseen-link" href="#" data-goto="lmth.tsiltcudorp/">Product List</a>
<br>
<br>
<br>SEEN BY USER
<br>
<br><a class="unseen-link" href="/productlist.html"
<br>data-goto="lmth.tsiltcudorp/">Product List</a>
<br>
<br>
<br>
<br>function prepareMissingLinks() {
<br> var stringReverse = function(string) {
<br> return string.split('').reverse().join('');
<br> };
<br> var $hiddenLink = $('.unseen-link');
<br>
<br> $hiddenLink.each(function() {
<br> $(this).attr("href", stringReverse($(this).data('goto')));
<br> });
<br>}
<br>
<br>
<br>
<br>I had an earlier implementation of this using the hover event but that
<br>doesn't work for touchscreen devices. This works on desktop and
<br>mobile, and is also simpler.krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-35361845943436967982014-02-26T12:11:00.001+11:002014-02-26T12:11:48.586+11:00How to change extension of multiple files in Linux?When files are in same folder:
<br>
<br>rename 's/.abc$/.edefg/' *.abc
<br>
<br>
<br>Recursively rename files:
<br>
<br># Bash
<br># Also requires GNU or BSD find(1)
<br># Recursively change all *.foo files to *.bar
<br>
<br>find . -type f -name '*.foo' -print0 | while IFS= read -r -d '' f; do
<br> mv -- "$f" "${f%.foo}.bar"
<br>done
<br>
<br>
<br>
<br>From:
<br><a href="http://askubuntu.com/questions/35922/how-to-change-extension-of-multiple-files-from-command-line">http://askubuntu.com/questions/35922/how-to-change-extension-of-multiple-files-from-command-line</a>
<br>
<br>Also see:
<br>
<br><a href="http://mywiki.wooledge.org/BashFAQ/030">http://mywiki.wooledge.org/BashFAQ/030</a>krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-70837385875738670672014-02-12T14:02:00.001+11:002014-02-12T14:02:37.427+11:00@RetryOnFailure annotation using Aspect from JCABI libraryUse this annotation to make repeated calls on failure for an idempotent method
<br>
<br><a href="http://www.jcabi.com/jcabi-aspects/annotation-retryonfailure.html">http://www.jcabi.com/jcabi-aspects/annotation-retryonfailure.html</a>krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-2956890295484125272014-02-12T10:44:00.001+11:002014-02-12T10:44:22.110+11:00Validate user-inputted URLs using Google Safe Browsing APIUse this API to get a database of URLs from Google and verify them
<br>locally. They also have an earlier version of the API but you need to
<br>make a remote call. This is better as the client is the only one that
<br>knows about the URLs it is verifying.
<br>
<br><a href="https://developers.google.com/safe-browsing/developers_guide_v2">https://developers.google.com/safe-browsing/developers_guide_v2</a>krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-86601053048597094392014-02-06T07:43:00.001+11:002014-02-06T07:43:45.428+11:00Notes: Example of image data embedded in HTMLThis is a div that appears on the Onion above an article when you've
<br>reached 5 articles already, asking you to subscribe. The image
<br>information is embedded in base64 on the div itself.
<br>
<br>
<br><div style="background-image:
<br>url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RDhCQzBDREZCQ0ZGMTFFMEIxQkFCQ0MxOEQzMzc5NTEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RDhCQzBDRTBCQ0ZGMTFFMEIxQkFCQ0MxOEQzMzc5NTEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpEOEJDMENEREJDRkYxMUUwQjFCQUJDQzE4RDMzNzk1MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpEOEJDMENERUJDRkYxMUUwQjFCQUJDQzE4RDMzNzk1MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PoOauxEAAAALSURBVAgdYzA+AwABNQEAGVbmvQAAAABJRU5ErkJggg%3D%3D);
<br>z-index: 99998; position: absolute; top: 0px; left: 0px; width: 100%;
<br>height: 3198px;"></div>krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-17688288231683936092014-02-04T14:23:00.001+11:002014-02-04T14:23:33.165+11:00Java: (Spring) Getting subset of a list for paged displayPagedListHolder - one of those Spring classes that you wish you've
<br>been using for the past 10 years
<br>
<br>Given a
<br>1. list of items
<br>2. page number and
<br>3. number of items per page
<br>
<br>Return the part of the list to be displayed on the page
<br>
<br>
<br>PagedListHolder<PopularSearch> pagedListHolder = new
<br>PagedListHolder<PopularSearch>(sourceList);
<br>pagedListHolder.setPage(pageNumber);
<br>pagedListHolder.setPageSize(itemCountPerPage);
<br>
<br>List<PopularSearch> tmp = pagedListHolder.getPageList();krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0tag:blogger.com,1999:blog-12794049.post-57851894802172086552014-01-31T14:56:00.001+11:002014-01-31T14:56:48.502+11:00Doubleclick for Publishers reference materialFrom: <a href="https://productforums.google.com/forum/#!category-topic/dfp/getting-started/208IT9kC6Xo">https://productforums.google.com/forum/#!category-topic/dfp/getting-started/208IT9kC6Xo</a>
<br>
<br>For Premium
<br>
<br>DFP Premium Help Center
<br><a href="https://support.google.com/dfp_premium/">https://support.google.com/dfp_premium/</a>
<br>
<br>Please remember that are two main ways to contact DFP. There is a
<br>Contact Us link on all DFP Premium support page (near the upper right
<br>hand part of the page). There is also a Report a Bug link in your DFP
<br>account (also in the upper right hand corner of your page).
<br>
<br>Getting Started Guide (high level overview)
<br><a href="https://support.google.com/dfp_premium/answer/184981">https://support.google.com/dfp_premium/answer/184981</a>
<br>
<br>Training
<br><a href="https://support.google.com/dfp_premium/answer/3419426">https://support.google.com/dfp_premium/answer/3419426</a>
<br>
<br>Partner Directory
<br><a href="https://support.google.com/dfp_premium/answer/2616938">https://support.google.com/dfp_premium/answer/2616938</a>
<br>
<br>DFP Training Videos:
<br><a href="http://www.youtube.com/dfp">http://www.youtube.com/dfp</a>
<br>
<br>Release Notes
<br><a href="https://support.google.com/dfp_premium/answer/179039">https://support.google.com/dfp_premium/answer/179039</a>
<br>
<br>
<br>Other Resources
<br>
<br>Google also provides additional tools to webmasters to help you track
<br>traffic and improve your search rankings. If you have not signed up
<br>already, you might want to at least take a quick look at them.
<br>
<br>Google Analytics
<br><a href="http://www.google.com/analytics/">http://www.google.com/analytics/</a>
<br>
<br>Google Webmaster Tools
<br><a href="http://www.google.com/webmasters/">http://www.google.com/webmasters/</a>
<br>
<br>
<br>Webinars
<br>
<br>Google has been releasing quite a few webinars that people maybe
<br>interested in. While not always specific to DFP, many of them are
<br>helpful for webmasters and advertising in general.
<br>
<br>You can register for Google Webinars here:
<br><a href="http://www.google.com/ads/experienced/webinars.html">http://www.google.com/ads/experienced/webinars.html</a>
<br>
<br>Or use their Calendar to see upcoming Webinars
<br><a href="https://www.google.com/calendar/embed?src=google.com_fqpk56cl9ck36np1ip263m2hks%40group.calendar.google.com">https://www.google.com/calendar/embed?src=google.com_fqpk56cl9ck36np1ip263m2hks%40group.calendar.google.com</a>krangsquaredhttp://www.blogger.com/profile/18015700958645737525noreply@blogger.com0