PicoContainer
  1. PicoContainer
  2. PICO-322

Cannot instantiate objects that have an specific collection in their constructor.

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: 2.5
    • Component/s: PicoContainer (Java)
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      Test cases:

      Plunk them into AbstractPicoContainerTest for demo:

          /**
           * Sample class that demonstrates literal collection handling.
           */
          static class Searcher {
          	private final List<String> searchPath;
          	
          	public Searcher(List<String> searchPath) {
          		this.searchPath = searchPath;
          	}   
          	
          	public List<String> getSearchPath() {
          		return searchPath;
          	}
          }
          
          @Test public void canInstantiateAutowiredCollectionThatAreDefinedExplicitly() {
          	MutablePicoContainer pico = this.createPicoContainer(null);
          	List<String> searchPath = new ArrayList<String>();
          	searchPath.add("a");
          	searchPath.add("b");
          	
          	pico.addComponent("searchPath",searchPath)
          		.addComponent(Searcher.class);
          	
          	assertNotNull(pico.getComponent(Searcher.class));
          	assertNotNull(pico.getComponent(Searcher.class).getSearchPath());
          }
          
          @Test public void canInstantiateExplicitCollectionWithComponentParameter() {
          	MutablePicoContainer pico = this.createPicoContainer(null);
          	List<String> searchPath = new ArrayList<String>();
          	searchPath.add("a");
          	searchPath.add("b");
          	
          	pico.addComponent("searchPath",searchPath)
          		.addComponent(Searcher.class, Searcher.class, new ComponentParameter("searchPath"));
          	
          	assertNotNull(pico.getComponent(Searcher.class));
          	assertNotNull(pico.getComponent(Searcher.class).getSearchPath());
          }
      

        Issue Links

          People

          • Assignee:
            Unassigned
            Reporter:
            Michael Rimov
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: