{
  "version": "https://jsonfeed.org/version/1.1",
  "title": "chem-bla-ics",
  "description": "Chemblaics (pronounced chem-bla-ics) is the science that uses open science and computers to solve problems in chemistry, biochemistry and related fields.",
  "home_page_url": "https://chem-bla-ics.linkedchemistry.info/",
  "feed_url": "https://chem-bla-ics.linkedchemistry.info/2008/12/26/state-of-cdk-120.json",
  "icon": "https://chem-bla-ics.linkedchemistry.info/assets/images/chem-bla-ics_logo.png",
  "language": "en",
  "authors": [
    {
      "name": "Egon Willighagen",
      "url": "https://orcid.org/0000-0001-7542-0286",
      "_orcid": "0000-0001-7542-0286"
    }
  ],
  "items": [

    {
      "id": "https://doi.org/10.59350/xgy88-kfs02",
      "url": "https://chem-bla-ics.linkedchemistry.info/2008/12/26/state-of-cdk-120.html",
      "title": "State of CDK 1.2.0...",
      "content_html": "<p>The reason why I have not blogged in more than two weeks, was that I was hoping to blog about the CDK 1.2.0 release. This was originally aimed at\nSeptember, slipped into October, November and then December. There were only three show stoppers (see <a href=\"https://apps.sourceforge.net/mediawiki/cdk/index.php?title=CDK_1.2_TODO\">this wiki page</a>),\none of which the <a href=\"http://cheminfo.informatics.indiana.edu/~rguha/code/java/nightly/api/org/openscience/cdk/interfaces/IChemObject.html\">IChemObject</a>\ninterfaces were not properly tested.</p>\n\n<p>The problem was that the unit tests for the methods in superinterfaces were not applied to implementations of subinterfaces.\nFor example, the unit test for <code class=\"language-plaintext highlighter-rouge\">IElement.getSymbol()</code> was not applied to the class <code class=\"language-plaintext highlighter-rouge\">Atom</code>, which implements <code class=\"language-plaintext highlighter-rouge\">IAtom</code> which\nis a subinterfaces of <code class=\"language-plaintext highlighter-rouge\">IElement</code>.</p>\n\n<p>In fixing this, I had to take some hurdles. For example: the unit test classes used a set up following the implementations; CDK 1.2.x has three\nimplementations of the interfaces: data, datadebug and nonotify. The last does not send around update notifications, and rough tests indicate it\nis about 10% faster. The second implementation sends messages to the debugger for every modification of the data classes, which is, clearly,\nuseful for debugging purposes.</p>\n\n<p>However, the JUnit4 test classes were basically doing the same. The unit test <code class=\"language-plaintext highlighter-rouge\">DebugAtomTest</code> inherited form <code class=\"language-plaintext highlighter-rouge\">AtomTest</code>, and only overwrote\ncustomizations. <code class=\"language-plaintext highlighter-rouge\">AtomTest</code>, itself, inherited from <code class=\"language-plaintext highlighter-rouge\">ElementTest</code>. That’s where things got broken. In the single implementation set up, this\nwould have been fine, but to allow testing of all three implementations, <code class=\"language-plaintext highlighter-rouge\">getBuilder()</code> had to be used.</p>\n\n<p>And when I implemented that, I did not realize that <code class=\"language-plaintext highlighter-rouge\">ElementTest</code> would do a test like:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"nc\">IElement</span> <span class=\"n\">element</span> <span class=\"o\">=</span> <span class=\"n\">builder</span><span class=\"o\">.</span><span class=\"na\">newElement</span><span class=\"o\">();</span>\n<span class=\"c1\">// test IElement functionality</span>\n</code></pre></div></div>\n\n<p>However, while the use of builder ensure testing of all three implementations, it does <strong>not</strong> run these tests on <code class=\"language-plaintext highlighter-rouge\">IAtom</code> implementations.</p>\n\n<p>The followed a long series of patches to get this fixed. One major first patch, was to define unit test frameworks like <code class=\"language-plaintext highlighter-rouge\">AbstractElementTest</code>\nwhich formalized running unit tests on any implementation, as I noticed that quite a few tests were still testing one particular implementation.\nThis allowed <code class=\"language-plaintext highlighter-rouge\">DebugElementTest</code> to extend <code class=\"language-plaintext highlighter-rouge\">AbstractElementTest</code>, instead of <code class=\"language-plaintext highlighter-rouge\">ElementTest</code>, which would now extend <code class=\"language-plaintext highlighter-rouge\">AbstractElementTest</code> too.</p>\n\n<p>OK, with that out of the way, it was time to fix running the unit test for <code class=\"language-plaintext highlighter-rouge\">IElement.getSymbol()</code> on <code class=\"language-plaintext highlighter-rouge\">IAtom.getSymbol()</code>, which required the\nremoval of the use of <code class=\"language-plaintext highlighter-rouge\">IChemObjectBuilder</code> implementations. So, I introduced <code class=\"language-plaintext highlighter-rouge\">newChemObject()</code> which would return a fresh instance of the\nactually tested implementation. That is, <code class=\"language-plaintext highlighter-rouge\">DebugAtomTest</code> would return a new <code class=\"language-plaintext highlighter-rouge\">DebugAtom</code>, and the <code class=\"language-plaintext highlighter-rouge\">getSymbol()</code> test would now run on\n<code class=\"language-plaintext highlighter-rouge\">DebugAtom</code> and not <code class=\"language-plaintext highlighter-rouge\">DebugElement</code>. Good.</p>\n\n<p>No, not good. The actual implementation I was using, looks like:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"kd\">public</span> <span class=\"kd\">class</span> <span class=\"nc\">DebugElementTest</span> <span class=\"n\">extend</span> <span class=\"nc\">AbstractElementTest</span> <span class=\"o\">{</span>\n  <span class=\"nd\">@BeforeClass</span> <span class=\"kd\">public</span> <span class=\"kd\">static</span> <span class=\"kt\">void</span> <span class=\"nf\">setup</span><span class=\"o\">()</span> <span class=\"o\">{</span>\n    <span class=\"n\">setChemObject</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">DebugElement</span><span class=\"o\">());</span>\n  <span class=\"o\">}</span>\n<span class=\"o\">}</span>\n\n<span class=\"kd\">public</span> <span class=\"kd\">abstract</span> <span class=\"kd\">class</span> <span class=\"nc\">AbstractElementTest</span> <span class=\"n\">extend</span> <span class=\"nc\">AbstractChemObjectTest</span> <span class=\"o\">{</span>\n  <span class=\"nd\">@Test</span> <span class=\"kd\">public</span> <span class=\"kt\">void</span> <span class=\"nf\">testGetSymbol</span><span class=\"o\">()</span> <span class=\"o\">{</span>\n    <span class=\"nc\">IElement</span> <span class=\"n\">element</span> <span class=\"o\">=</span> <span class=\"o\">(</span><span class=\"nc\">IElement</span><span class=\"o\">)</span><span class=\"n\">newChemObject</span><span class=\"o\">();</span>\n    <span class=\"c1\">// do testing</span>\n  <span class=\"o\">}</span>\n<span class=\"o\">}</span>\n\n<span class=\"kd\">public</span> <span class=\"kd\">abstract</span> <span class=\"kd\">class</span> <span class=\"nc\">AbstractChemObjectTest</span> <span class=\"o\">{</span>\n  <span class=\"kd\">private</span> <span class=\"nc\">IChemObject</span> <span class=\"n\">testedObject</span><span class=\"o\">;</span>\n  <span class=\"kd\">public</span> <span class=\"kd\">static</span> <span class=\"nf\">setChemObject</span><span class=\"o\">(</span><span class=\"nc\">IChemObject</span> <span class=\"n\">object</span><span class=\"o\">)</span> <span class=\"o\">{</span>\n    <span class=\"k\">this</span><span class=\"o\">.</span><span class=\"na\">testedObject</span> <span class=\"o\">=</span> <span class=\"n\">object</span><span class=\"o\">;</span>\n  <span class=\"o\">}</span>\n  <span class=\"kd\">public</span> <span class=\"nc\">IChemObject</span> <span class=\"nf\">setChemObject</span><span class=\"o\">(</span><span class=\"nc\">IChemObject</span> <span class=\"n\">object</span><span class=\"o\">)</span> <span class=\"o\">{</span>\n    <span class=\"k\">return</span> <span class=\"o\">(</span><span class=\"nc\">IChemObject</span><span class=\"o\">)</span><span class=\"n\">testedObject</span><span class=\"o\">.</span><span class=\"na\">clone</span><span class=\"o\">();</span>\n  <span class=\"o\">}</span> <span class=\"c1\">// just imagine it has try/catch here too</span>\n\n  <span class=\"c1\">// and here the tests for the IChemObject API</span>\n  <span class=\"nd\">@Test</span> <span class=\"kd\">public</span> <span class=\"kt\">void</span> <span class=\"nf\">testGetProperties</span><span class=\"o\">()</span> <span class=\"o\">{</span>\n    <span class=\"nc\">IChemObject</span> <span class=\"n\">element</span> <span class=\"o\">=</span> <span class=\"o\">(</span><span class=\"nc\">IChemObject</span><span class=\"o\">)</span><span class=\"n\">newChemObject</span><span class=\"o\">();</span>\n    <span class=\"c1\">// do testing</span>\n  <span class=\"o\">}</span>\n<span class=\"o\">}</span>\n</code></pre></div></div>\n\n<p>Excellent! No.</p>\n\n<p>Well, yes. The above system works, but made many unit tests fail, because of bugs in <code class=\"language-plaintext highlighter-rouge\">clone()</code> methods. The full scope has to be explored,\nbut at least <code class=\"language-plaintext highlighter-rouge\">IPolymer.clone()</code> is not doing what I would expect it to do. Either I am wrong, and need to overwrite the clone unit tests\nof superinterfaces in <code class=\"language-plaintext highlighter-rouge\">AbstractPolymerTest</code>, or the implementations needs fixing. I emailed the cdk-devel mailing list and filed a bug\nreport. But having about 1000 unit tests fail, because of clone broken, is something I did not like. For example, as it makes bug fixing\nmore difficult.</p>\n\n<p>So, next step was to find an approach that did not require clone, but give some interesting insights in the Java language. JUnit4 requires\nthe <code class=\"language-plaintext highlighter-rouge\">@BeforeClass</code> method to be static. This means I cannot have a non-static <code class=\"language-plaintext highlighter-rouge\">DebugElementTest</code> method return an instance. And, you\ncannot overwrite a static method! That had never occured to me in the past. <code class=\"language-plaintext highlighter-rouge\">DebugElementTest.newChemObject()</code> does not overwrite\n<code class=\"language-plaintext highlighter-rouge\">AbstractChemObjectTest.newChemObject</code> which is somewhere upstream.</p>\n\n<p>But, after discussing matters with Carl, I ended up with this approach:</p>\n\n<div class=\"language-java highlighter-rouge\"><div class=\"highlight\"><pre class=\"highlight\"><code><span class=\"kd\">public</span> <span class=\"kd\">abstract</span> <span class=\"kd\">class</span> <span class=\"nc\">AbstractChemObjectTest</span> <span class=\"kd\">extends</span> <span class=\"nc\">CDKTestCase</span> <span class=\"o\">{</span>\n  <span class=\"kd\">private</span> <span class=\"kd\">static</span> <span class=\"nc\">ITestObjectBuilder</span> <span class=\"n\">builder</span><span class=\"o\">;</span>\n  <span class=\"kd\">public</span> <span class=\"kd\">static</span> <span class=\"kt\">void</span> <span class=\"nf\">setTestObjectBuilder</span><span class=\"o\">(</span><span class=\"nc\">ITestObjectBuilder</span> <span class=\"n\">builder</span><span class=\"o\">)</span> <span class=\"o\">{</span>\n    <span class=\"nc\">AbstractChemObjectTest</span><span class=\"o\">.</span><span class=\"na\">builder</span> <span class=\"o\">=</span> <span class=\"n\">builder</span><span class=\"o\">;</span>\n  <span class=\"o\">}</span>\n  <span class=\"kd\">public</span> <span class=\"kd\">static</span> <span class=\"nc\">IChemObject</span> <span class=\"nf\">newChemObject</span><span class=\"o\">()</span> <span class=\"o\">{</span>\n    <span class=\"k\">return</span> <span class=\"nc\">AbstractChemObjectTest</span><span class=\"o\">.</span><span class=\"na\">builder</span><span class=\"o\">.</span><span class=\"na\">newTestObject</span><span class=\"o\">();</span>\n  <span class=\"o\">}</span>\n<span class=\"o\">}</span>\n\n<span class=\"kd\">public</span> <span class=\"kd\">interface</span> <span class=\"nc\">ITestObjectBuilder</span> <span class=\"o\">{</span>\n  <span class=\"kd\">public</span> <span class=\"nc\">IChemObject</span> <span class=\"nf\">newTestObject</span><span class=\"o\">();</span>\n<span class=\"o\">}</span>\n\n<span class=\"kd\">public</span> <span class=\"kd\">class</span> <span class=\"nc\">DebugAtomTest</span> <span class=\"kd\">extends</span> <span class=\"nc\">AbstractAtomTest</span> <span class=\"o\">{</span>\n  <span class=\"nd\">@BeforeClass</span> <span class=\"kd\">public</span> <span class=\"kd\">static</span> <span class=\"kt\">void</span> <span class=\"nf\">setUp</span><span class=\"o\">()</span> <span class=\"o\">{</span>\n    <span class=\"n\">setTestObjectBuilder</span><span class=\"o\">(</span><span class=\"k\">new</span> <span class=\"nc\">ITestObjectBuilder</span><span class=\"o\">()</span> <span class=\"o\">{</span>\n      <span class=\"kd\">public</span> <span class=\"nc\">IChemObject</span> <span class=\"nf\">newTestObject</span><span class=\"o\">()</span> <span class=\"o\">{</span>\n        <span class=\"k\">return</span> <span class=\"k\">new</span> <span class=\"nf\">DebugAtom</span><span class=\"o\">();</span>\n      <span class=\"o\">}</span>\n    <span class=\"o\">});</span>\n  <span class=\"o\">}</span>\n<span class=\"o\">}</span>\n</code></pre></div></div>",
      "summary": "The reason why I have not blogged in more than two weeks, was that I was hoping to blog about the CDK 1.2.0 release. This was originally aimed at September, slipped into October, November and then December. There were only three show stoppers (see this wiki page), one of which the IChemObject interfaces were not properly tested.",
      
      "date_published": "2008-12-26T00:00:00+00:00",
      "date_modified": "2008-12-26T00:00:00+00:00",
      "tags": ["cdk","junit","java"],
      
      
      
      
      
      
        "authors": [ { "name": "Egon Willighagen", "url": "https://orcid.org/0000-0001-7542-0286" } ]
      
    }

  ]
}
