Skip to content

Instantly share code, notes, and snippets.

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Body body = createBody();
@Component( modules = RandomInjectionModule.class )
public interface Doctor {
Body injectBlood();
}
@jose-mgmaestre
jose-mgmaestre / RandomInjectionModule.java
Last active April 16, 2018 13:17
This class will inject random blood objects for a Blood interface
@Module
public class RandomInjectionModule {
private static Blood blood;
public RandomInjectionModule() {
}
@Provides
static Blood provideBlood(){
public class A_Blood extends Blood{
@Override
public String getKindOfBlood() {
return "A";
}
}
public abstract class Blood {
public abstract String getKindOfBlood();
}
@jose-mgmaestre
jose-mgmaestre / Body.java
Created April 13, 2018 15:35
Body with Blood
public class Body {
@Inject
Blood blood;
@Inject
public Body(){}
public class Person{
Body body;
@Inject
public Person(Body body){
this.body = body;
}
}
@jose-mgmaestre
jose-mgmaestre / Body.java
Created April 13, 2018 15:25
Body as simple as possible to explain the injection
package com.ricston.injectionexample.domain;
import com.ricston.injectionexample.domain.com.ricston.injectionexample.domain.blood.Blood;
import javax.inject.Inject;
public class Body {
@Inject
public Body(){}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:META-INF/spring/testContext.xml" })
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
public class MultiTenantConnectionProviderTest {
...
@Autowired
MultiTenantConnectionProviderImpl multitenancyConnectionProvider;
@jose-mgmaestre
jose-mgmaestre / CurrentTenantIdentifierResolverImpl.java
Last active January 17, 2018 14:01
Multitenancy junit test : Using a global tenant
/**
* It specify what Tenant should be used:
* <p>
* <p>
* There are 2 modes of resolving the identifier using {@link #resolveCurrentTenantIdentifier()}:
*
* <li> Using a global tenant identifier for junit testing
* <li> Using the http session to get the tenant for deployed applications
*