### Question:
SmartWroModelFactory extends AbstractWroModelFactory { @Override public WroModel create() { if (factoryList == null) { factoryList = newWroModelFactoryFactoryList(); } if (factoryList != null) { final StringBuffer logMessageBuffer = new StringBuffer(); for (final WroModelFactory factory : factoryList) { try { injector.inject(factory); final Class<? extends WroModelFactory> factoryClass = factory.getClass().asSubclass(WroModelFactory.class); logMessageBuffer.append(" Using " + getClassName(factoryClass) + " for model creation..\n"); return factory.create(); } catch (final WroRuntimeException e) { LOG.debug("[FAIL] creating model... will try another factory: {}", e.getCause()); logMessageBuffer.append("[FAIL] Model creation using " + getClassName(factory.getClass()) + " failed. Trying another ...\n"); logMessageBuffer.append("[FAIL] Exception occured while building the model using: " + getClassName(factory.getClass()) + " " + e.getMessage()); if (!autoDetectWroFile && e.getCause() instanceof IOException) { throw e; } } } LOG.error(logMessageBuffer.toString()); } throw new WroRuntimeException("Cannot create model using any of provided factories"); }  static SmartWroModelFactory createFromStandaloneContext(final StandaloneContext context); SmartWroModelFactory setWroFile(final File wroFile); @Override WroModel create(); SmartWroModelFactory setFactoryList(final List<WroModelFactory> factoryList); SmartWroModelFactory setAutoDetectWroFile(final boolean autoDetectWroFile); static final String ALIAS; }### Answer:
@Test(expected = WroRuntimeException.class) public void testDefaultInstance() throws Exception { factory = new SmartWroModelFactory(); injector.inject(factory); factory.create(); }
@Test(expected = WroRuntimeException.class) public void cannotCreateModelWhenNullListOfFactoriesProvided() throws Exception { factory = new SmartWroModelFactory() { @Override protected List<WroModelFactory> newWroModelFactoryFactoryList() { return null; } }; injector.inject(factory); factory.create(); }
@Test public void shouldCreateModelEvenWhenFirstAttemptFails() throws Exception { factory = createTestSmartModelFactory(); Assert.assertNotNull(factory.create()); }
@Test public void shouldInjectInnerModelFactories() { final SmartWroModelFactory factory = new SmartWroModelFactory() { @Override protected List<WroModelFactory> newWroModelFactoryFactoryList() { final List<WroModelFactory> list = new ArrayList<WroModelFactory>(); list.add(new CustomWroModel() { @Override public WroModel create() { Assert.assertNotNull("Should have an injected locator!", uriLocatorFactory); return new WroModel(); } }); return list; } }; injector.inject(factory); Assert.assertNotNull(factory.create()); }