PicoContainer
  1. PicoContainer
  2. PICO-34

fix these 'registry style' unit test cases.

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0-beta-1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      I've attached a bunch of unit test cases for using RegistrationPicoContainer in a registry style - using a mixture of interface classes or String keys.

      There seems to be 2 bugs outstanding right now. The main one is - changing DefaultPicoContainer's getComponents() method to this...

      public Object[] getComponents()

      { return componentKeyToInstanceMap.values().toArray(); }

      which fixes it - though it breaks some other tests.

      The other thing that doesn't seem to work is

      pico.registerComponent("foo", SomeClass.class):
      pico.hasComponent("foo");
      pico.getComponent("foo");

      So we're close. I hope to provide patches to fix this soon if noone else jumps in first.

      1. patch.txt
        9 kB
        james strachan

        Activity

        Hide
        james strachan added a comment -

        Here's the test case. doesn't quite pass yet.

        Show
        james strachan added a comment - Here's the test case. doesn't quite pass yet.
        james strachan made changes -
        Field Original Value New Value
        Attachment patch.txt [ 10465 ]
        james strachan made changes -
        Project NanoContainer [ 10121 ] PicoContainer [ 10120 ]
        Key NANO-6 PICO-34
        Hide
        Aslak Hellesøy added a comment -

        I haven't looked at your tests, but there is a reason why the current getComponents() implementation is like it is:

        See the big comment section in DefaultPicoContainer that I just submitted:

        http://picocontainer.cvs.codehaus.org/pico/src/java/picocontainer/defaults/DefaultPicoContainer.java.diff?r1=1.24&r2=1.25&cvsroot=picocontainer

        I haven't checked thoroughly, but ypur proposed change to a trivial implementation of getComponents() will break the HierarchicalPicoContainer. The present getComponents() code on CVS uses getComponentTypes() method. This method is overridden in HPC, but your more shorthand implementation bypasses it, thereby breaking some tests.

        Aslak

        Show
        Aslak Hellesøy added a comment - I haven't looked at your tests, but there is a reason why the current getComponents() implementation is like it is: See the big comment section in DefaultPicoContainer that I just submitted: http://picocontainer.cvs.codehaus.org/pico/src/java/picocontainer/defaults/DefaultPicoContainer.java.diff?r1=1.24&r2=1.25&cvsroot=picocontainer I haven't checked thoroughly, but ypur proposed change to a trivial implementation of getComponents() will break the HierarchicalPicoContainer. The present getComponents() code on CVS uses getComponentTypes() method. This method is overridden in HPC, but your more shorthand implementation bypasses it, thereby breaking some tests. Aslak
        Hide
        james strachan added a comment -

        Thanks for that Aslak.

        I'll have a look into it all at tonights GeekNight and see if I can figure out whats going on.

        Show
        james strachan added a comment - Thanks for that Aslak. I'll have a look into it all at tonights GeekNight and see if I can figure out whats going on.
        Hide
        Jon Tirsen added a comment -

        Okay, fixed the tests.

        The first bug: of course, that

        Second problem: Slight misunderstanding, the tests work after you do instantiateComponents():
        pico.registerComponent(WilmaImpl.class);
        assertFalse(pico.hasComponent(WilmaImpl.class)); // doesn't work yet
        pico.instantiateComponents(); // <--- don't forget!!
        assertTrue(pico.hasComponent(WilmaImpl.class)); // now it works!

        Show
        Jon Tirsen added a comment - Okay, fixed the tests. The first bug: of course, that Second problem: Slight misunderstanding, the tests work after you do instantiateComponents(): pico.registerComponent(WilmaImpl.class); assertFalse(pico.hasComponent(WilmaImpl.class)); // doesn't work yet pico.instantiateComponents(); // <--- don't forget!! assertTrue(pico.hasComponent(WilmaImpl.class)); // now it works!
        Jon Tirsen made changes -
        Status Unassigned [ 1 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.0-beta-1 [ 10144 ]
        Hide
        james strachan added a comment -

        DOH! Thanks Jon!

        Show
        james strachan added a comment - DOH! Thanks Jon!

          People

          • Assignee:
            Unassigned
            Reporter:
            james strachan
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: