<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nancy Deschenes</title>
    <description>The latest articles on DEV Community by Nancy Deschenes (@nancyd).</description>
    <link>https://dev.to/nancyd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F34326%2F09e73685-6d33-4aed-a2e0-75c2db558eea.jpeg</url>
      <title>DEV Community: Nancy Deschenes</title>
      <link>https://dev.to/nancyd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nancyd"/>
    <language>en</language>
    <item>
      <title>Grails: Mocking domain objects/criteria that reference Joda Time objects</title>
      <dc:creator>Nancy Deschenes</dc:creator>
      <pubDate>Wed, 11 Jul 2018 21:12:41 +0000</pubDate>
      <link>https://dev.to/nancyd/grails-mocking-domain-objectscriteria-that-reference-joda-time-objects-a8o</link>
      <guid>https://dev.to/nancyd/grails-mocking-domain-objectscriteria-that-reference-joda-time-objects-a8o</guid>
      <description>&lt;p&gt;I can rant about the difficulties of handling time correctly when programming like anyone else who has ever tried. I can also criticize the default date and time objects in Java, but I will just say this: Just use Joda Time. You can also take a peek at an article I wrote a while back for &lt;a href="https://smartbear.com/blog/develop/date-and-time-manipulation-in-java-using-jodatime/"&gt;more details&lt;/a&gt;. I even use Joda Time in my domain objects in Grails.  It requires a small amount of configuration, but it is well worth it.  See the &lt;a href="https://grails.org/plugin/joda-time?skipRedirect=true"&gt;plugin&lt;/a&gt; for more details.&lt;/p&gt;

&lt;p&gt;Where things get a bit more complicated is when I want to test my GORM criteria when the criteria involves an &lt;code&gt;org.joda.time.DateTime&lt;/code&gt;.  For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** My domain object */
class Membership {
  User user
  DateTime memberSince
}

/** My service */
class MembershipService {
  boolean transactional = true

  /** Return users who have been around for at least 5 years */
  List&amp;lt;User&amp;gt; findOldUsers() {
    Membership.createCriteria().list() {
      user {
        eq('deleted', false)
      }
      lte('memberSince', new DateTime().minusYears(5))
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, the test:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@Mock([Membership, User])
@TestFor(MembershipService)
class MembershipServiceSpec extends Specification {
  def "findOldUsers does not return anything if all the users have been around less than a year"() {
    given:
      User u1 = new User().save() 
      // or save(false) if there are constraints we want to ignore for the time being)
      new Membership(user: user, memberSince: new DateTime().minusMonths(4)).save();

    expect:
      service.findOldUsers().isEmpty()
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;What happens? well....&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java.lang.IllegalArgumentException: Property [memberSince] is not a valid property of class [com.mycompany.Membership]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Of course, the GORM mocking framework doesn't know about DateTime, so it didn't register it as a property of Membership.  To fix this, all we need to do is, first tell the mocking framework about Joda Time classes, and second, we have to mock our domain objects &lt;strong&gt;after&lt;/strong&gt; we mock the Joda Time classes.  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import grails.plugin.jodatime.simpledatastore.SimpleMapJodaTimeMarshaller
@Mock(User)
@TestFor(MembershipService)
class MembershipServiceSpec extends Specification {
  setup() {
    SimpleMapJodaTimeMarshaller.initialize()
    mockDomain(Membership)
  }

  // [...]
}    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>grails</category>
      <category>gorm</category>
      <category>spock</category>
      <category>todayilearned</category>
    </item>
    <item>
      <title>Today, I learned that Tuple != Tuple2</title>
      <dc:creator>Nancy Deschenes</dc:creator>
      <pubDate>Thu, 10 May 2018 18:52:54 +0000</pubDate>
      <link>https://dev.to/nancyd/today-i-learned-that-tuple--tuple2-1opi</link>
      <guid>https://dev.to/nancyd/today-i-learned-that-tuple--tuple2-1opi</guid>
      <description>&lt;p&gt;Once upon a time, I wrote a service class that generates pairs of users.  I thought to myself, "Ohh! I know this! I need to return a list of tuples!"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Tuple&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;getUserMatches&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Tuple&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;User&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;returnVal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;moreUsers&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;getUserA&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;User&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;getUserB&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; 
    &lt;span class="n"&gt;returnVal&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Tuple&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test the code.  The code runs.  All is good. Move on.&lt;/p&gt;

&lt;p&gt;Later, a co-worker asks, "why aren't the tests running?" What? no, my tests run, I'm sure! On closer inspection, not only do the tests not pass, they fail to compile.  I shake my head.  I can't imagine...  What's worse, IntelliJ shows absolutely no compilation problems. Without a compilation error, it's hard to fix the problem. What I get instead is an exception:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;java.lang.reflect.MalformedParameterizedTypeException
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:60)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.&amp;lt;init&amp;gt;(ParameterizedTypeImpl.java:53)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:95)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
[...]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.rootLoader(GrailsStarter.java:236)
    at org.codehaus.groovy.grails.cli.support.GrailsStarter.main(GrailsStarter.java:264)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some googling leads me &lt;a href="https://binarybuffer.com/post/2013-01-28-java-lang-reflect-malformedparameterizedtypeexception-exception-in-grails-when-using-httpbuilder/"&gt;this blog post&lt;/a&gt;.  Ah, okay, I need to find out where I managed to parametrize a class incorrectly.&lt;/p&gt;

&lt;p&gt;The exception only occurs when compiling the tests, so that where I look. I try to get the system to only compile some of the tests, to figure out which is causing the problem.  Finally find that the test for my service above is responsible. I still have no idea what's wrong with it, mind you.  All I know is that when I try to compile it, it fails with the dreaded &lt;code&gt;java.lang.reflect.MalformedParameterizedTypeException&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I comment out half the file. The problem still happens.  I comment out another quarter. Another eighth.  Until all I have left is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="nd"&gt;@TestFor&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;UserMergeService&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserMergeServiceSpec&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;Specification&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And it still crashes the compiler.  I comment out the annotation, and it compiles! I put the whole file back in, and as long as the annotation is commented out, it works.&lt;/p&gt;

&lt;p&gt;It was positively mystifying.&lt;/p&gt;

&lt;p&gt;I tried to approach it from the other end. I set a breakpoint where the &lt;code&gt;MalformedParameterizedTypeException&lt;/code&gt; was thrown, and walked up the stack, and looked at local values, and...  there's my Tuple.  I look at the definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Tuple&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="n"&gt;AbstractList&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hm. That's not parametrized.  How do you parametrize a Tuple, then?&lt;/p&gt;

&lt;p&gt;That's when I found &lt;a href="http://mrhaki.blogspot.ca/2016/03/groovy-goodness-using-tuples.html"&gt;this blog post&lt;/a&gt; that cleared everything up.&lt;/p&gt;

&lt;p&gt;Tuple is an immutable list of items, and is not parametrizable.  Tuple2 is a pair of two things, and the class of those two things can be parametrized.&lt;/p&gt;

&lt;p&gt;I don't know why this was a problem only when running the tests; the code compiles and runs just fine on its own, and the "bad code" is in the Service class, not in the test, but the test must have tickled something... At least it's fixed!&lt;/p&gt;

</description>
      <category>todayilearned</category>
      <category>grails</category>
      <category>groovy</category>
      <category>spock</category>
    </item>
    <item>
      <title>Nancy Coded And Coded And Coded Some More</title>
      <dc:creator>Nancy Deschenes</dc:creator>
      <pubDate>Thu, 08 Mar 2018 22:48:01 +0000</pubDate>
      <link>https://dev.to/nancyd/nancy-deschenes-coded-and-coded-and-coded-some-more--7hn</link>
      <guid>https://dev.to/nancyd/nancy-deschenes-coded-and-coded-and-coded-some-more--7hn</guid>
      <description>&lt;p&gt;I have been meaning to post my introduction for some time now, and what better time to do it than today, March 8, 2018.&lt;/p&gt;

&lt;h1&gt;
  
  
  Once upon a time...
&lt;/h1&gt;

&lt;p&gt;It all started a long time ago. I as always curious.  I liked to build things with my blocks and bricks.  I liked to solve codes, and read mystery books (&lt;em&gt;Famous Five&lt;/em&gt; anyone?).  I was quiet and shy, and never too far from a book.  My first introduction to computers was when I went to my dad's work, where they had terminals connected to a powerful computer. He showed me how to direct a turtle across a screen to make it draw shapes. Well, it wasn't so much a turtle as an arrow, but sure, let's pretend it was turtle. Later, when my dad bought a computer for the family, I got to try even more things. Sometimes, he would suggest a particular exercise for me ("write a program that that can calculate the right number of quarters, dimes, nickels and pennies to represent an amount") and sometimes, I just wanted to know, "what would happen if I ..."&lt;/p&gt;

&lt;p&gt;During those years, most of my time was spent with girls. I had sisters, went to al all-girl school, figure skated, and attended Girl Guides. I don't remember anyone telling me that math was for boys.  I could see for myself that I did well in the topic, so if someone did mention it, I didn't pay attention. I read my books, played on the computer, and kept learning whatever I got my hands on. &lt;/p&gt;

&lt;h1&gt;
  
  
  In a university far from home...
&lt;/h1&gt;

&lt;p&gt;At first, I didn't think I would program for a living.  The university I wanted to attend only had a Computer Engineering degree, and I didn't have the grades to get into the Engineering school.  I was accepted in the BSc program, but I didn't know which major I was interested in.  Physics? Chemistry? Biochem? I started with Math.  I could always change later, when I had a better idea.  Maybe even transfer to Engineering.  "Why don't you do a BSc in Computer Science?" suggested my advisor. How could I have missed that option? It was the first year the program was given, and overall, it was a bit confusing; some courses were given by the Faculty of Science, others by Engineering.  That's when I discovered the Internet, chat programs, Usenet, email, modems!  They even had a lab full of NeXT machines! Those were such sleek machines, and so much fun to program!  The Interface Builder let you position ui components on application windows, hook up events to the controls by dragging a line between the two, it was so much fun!  Whenever I design a UI, even today, I wish for the ease and simplicity of the NeXTSTEP Interface Builder.  Okay, I might be a little nostalgic, and I may be remembering those years though pink colored lenses, but who can tell, it was a long long time ago! I can't say I noticed much in terms of sexism then. Sure, we were significantly outnumbered, but I didn't pay attention to it much.&lt;/p&gt;

&lt;p&gt;There was onc incident when another student, someone I hadn't noticed around much before, asked that I give him my assignment so he could copy it.  I refused, and he got upset. That answer didn't suit him, and he said, "If you're ever disrespectful of me ever again, I will break every bone in your body."  Others students nearby escorted him out of the student lounge unceremoniously. That was the last I saw him, but other female students reported similar encounters.  I was a little shaken, but at the same time, I saw how others stepped in to help. He clearly had issues... &lt;/p&gt;

&lt;h1&gt;
  
  
  I got a job
&lt;/h1&gt;

&lt;p&gt;Out of school, it's time for a job.  I was fortunate that I knew of an opening in another university.  I was hired.  I learned COBOL and SQL quickly to get up to speed. In my spare time, I worked on a chat program, so I wouldn't forget how to write in C. Then, for fun, I learned HTML. I discovered CGI programming in PERL, and in C, and got busy making things.  With a friend, we wrote one of the earliest content management system in PERL and db (Berkeley DB, a key-value database). I became a systems administrator for about a year.  Now I know that's not for me; I spent most of my time programming!  &lt;/p&gt;

&lt;p&gt;That's when I took the jump to full-time consulting.  I worked from home, made my hours.  I could go skating every friday afternoon, but I did work late into the night too.  I worked with the same friend on improving the content management system, developed various Java applet games, worked on an applet that could tell when a user was logged into the site, wrote an in-browser chat system, worked on large database, small databases, in PERL, then in Java. &lt;/p&gt;

&lt;p&gt;I kept on learning and coding. And developing and architecting systems and finding news ways of doing old things, just better. &lt;/p&gt;

&lt;h1&gt;
  
  
  And now...
&lt;/h1&gt;

&lt;p&gt;I am still learning.  I am the Technical Co-Founder for myTurn.com, a platform for lending libraries, rental, and asset tracking.  I still work from home.  Every morning, I get my three kids up for school, make lunches, push them so the two that can take the bus don't miss it, oh, wait, too late, drive them, and the third one to school, and get working!  Or maybe I'll go to my other office, at Starbucks, or my other office, the breakfast restaurant that doesn't mind if I stay there for a few hours, or...&lt;/p&gt;

&lt;p&gt;I love the flexibility, the challenge, the constant need to do better, for our customers, and for our customer's customers.  I love playing with new technologies, stretching my mind on new concepts and then finding how these concepts can be applied to improve the quality of my work.  I am as curious as ever, and I try to read as much as I can, fiction, non fiction, technical... I eat it all up.  When I find the time.&lt;/p&gt;

&lt;p&gt;And I still skate.  And I am now a scout leader (for boys and girls).  I guess some things don't change.&lt;/p&gt;

</description>
      <category>wecoded</category>
    </item>
  </channel>
</rss>
