MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.cool_menu, menu); getLayoutInflater().setFactory(new Factory() { public View onCreateView(String name, Context context, AttributeSet attrs) {
public void testGeneric(){ Factory factory = new Factory(new String[]{"config/beanForGenericTest.xml"}); GenericSimple<Integer> simpleInt = (GenericSimple<Integer>)factory.getClass("simpleInt"); System.out.println(simpleInt.get(Integer.valueOf(100))); Assert.assertTrue(simpleInt.get(Integer.valueOf(100)).equals(100)); GenericSimple<String> simpleString = (GenericSimple<String>)factory.getClass("simpleString"); System.out.println(simpleString.get(new String("Rockets go fast."))); Assert.assertTrue(simpleString.get("Rockets go fast.") .equals("Rockets go fast.")); }
public static Factory newInstance() { return Factory.builder().addFromServiceLoader() .addLocalMachines(LocalMachines.threadLocal()) .build(); }
@Override public String apply(Name<?> input) { return Factory.activationKey(input.getClazz(), input.getName()); } }));
public <T> LocalMachines set(int priority, NamedComponent<T> namedComponent) { addMachine(new SingletonFactoryMachine<>(priority, namedComponent)); return this; } }
/** * Prepares all the AutoPreparable components of this factory. */ public Factory prepare() { for (AutoPreparable preparable : queryByClass(AutoPreparable.class).findAsComponents()) { preparable.prepare(); } return this; }
/** * Starts all the AutoStartable components of this factory. */ public Factory start() { for (AutoStartable startable : queryByClass(AutoStartable.class).findAsComponents()) { startable.start(); } return this; }
/** * Builds and return all the component of given class. * * This is a shortcut for queryByClass(componentClass).findAsComponents() * * @param componentClass the class of the components to build and return * @param <T> the type of components * @return the set of components of given class */ public <T> Set<T> getComponents(Class<T> componentClass) { return queryByClass(componentClass).findAsComponents(); }
@Alternative(to = RestxSpecRepository.class) @restx.factory.When(name="restx.mode", value="test") public static class TestRestxSpecRepository extends HotReloadRestxSpecRepository { public TestRestxSpecRepository(RestxSpecLoader specLoader) { super(specLoader); } }
private static Factory.Builder newFactoryBuilder() { return Factory.builder() .addFromServiceLoader() .addLocalMachines(Factory.LocalMachines.threadLocal()) ; }
@Alternative(to = RestxSpecRepository.class) @restx.factory.When(name="restx.mode", value="infinirest") public static class InfinirestRestxSpecRepository extends HotReloadRestxSpecRepository { public InfinirestRestxSpecRepository(RestxSpecLoader specLoader) { super(specLoader); } } }
@Override protected void onCreate(Bundle savedInstanceState) { getLayoutInflater().setFactory(new Factory() {
private static Factory.Builder newFactoryBuilder() { return Factory.builder() .addFromServiceLoader() .addLocalMachines(Factory.LocalMachines.threadLocal()) ; }
@Alternative(to = RestxSpecRepository.class) @restx.factory.When(name="restx.mode", value="dev") public static class DevRestxSpecRepository extends HotReloadRestxSpecRepository { public DevRestxSpecRepository(RestxSpecLoader specLoader) { super(specLoader); } }
infl.setFactory(new Factory()
public void testFactoryIfNetworkResponseBuilderNotFound() { Factory factory = spy(new Factory()); when(factory.getNetworkResponseBuilderClass()).thenThrow( new ClassNotFoundException() ); // The rest of your test here } public void testFactoryIfNetworkResponseBuilderFound() { Factory factory = spy(new Factory()); when(factory.getNetworkResponseBuilderClass()).thenReturn( OkHttpNetworkResponse.Builder.class ); // The rest of your test here }
getLayoutInflater().setFactory( new Factory() {