SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
RoboGuice
DI & IoC framework for Android
Me
Software Engineer @ FICO Corp.
Programmer
@nuboat
https://github.com/nuboat
http://slideshare.net/nuboat/

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
RoboGuice
RoboGuice เป็ น framework
สําหรั บทํา Dependency Injection บน
Android, พั ฒนาจาก Google Guice
library. ลั กษณะคล้ายกั บ Spring &
EJB ของ JavaEE

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Normal Style

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
RoboGuice Style

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Requirements
Java 6 or 7
Maven
Android SDK (platform 18)
Coffee & Beer (up to you)

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Librarys
RoboGuice v3.0b-experimental
Google Guice v3.0
Roboelectric v1.0
Mockito v1.9.5
JUnit v4.8.2

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Advantage of RoboGuice
Clean code
Inherit Guice feature (Singleton, …)
Automate Testing
Log Framework

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Clean Code
RoboActivity not Activity

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Inheriting from the RoboGuice
RoboActivity

RoboFragmentActivity

RoboListActivity

RoboLauncherActivity

RoboExpandableListActivity

RoboService

RoboMapActivity

RoboIntentService

RoboPreferenceActivity

RoboFragment

RoboAccountAuthenticatorActivity

RoboListFragment

RoboActivityGroup

RoboDialogFragment

RoboTabActivity

etc.

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Inject ?
roboguice.inject.InjectView
roboguice.inject.InjectExtra
roboguice.inject.InjectFragment
roboguice.inject.InjectPreference
roboguice.inject.InjectResource
javax.inject.Inject (POJO)
@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Singleton - Threadsafe
@Singleton
public class Astroboy {
@Inject Application application;
@Inject Vibrator vibrator;
@Inject Random random;

public void say(final String something) {
// Make a Toast, using the current context as returned by the Context Provider
Toast.makeText(application, "Astroboy says, "" + something + """, Toast.LENGTH_LONG).show();
}
public void brushTeeth() {
vibrator.vibrate(new long[]{0, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, }, -1);
}
public String punch() {
final String expletives[] = new String[]{"POW!", "BANG!", "KERPOW!", "OOF!"};
return expletives[random.nextInt(expletives.length)];
}
}

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Test Random value
@Singleton
public class Astroboy {
public String punch() {
final String expletives[] =
new String[]{"POW!", "BANG!", "KERPOW!", "OOF!"};
return expletives[random.nextInt(expletives.length)];
}
...
}

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Test Code 1
@RunWith(RobolectricTestRunner.class)
public class Astroboy1Test {

protected Context context = new RoboActivity();
protected Astroboy astroboy = RoboGuice.getInjector(context).getInstance(Astroboy.class);

@Test
public void stringShouldEndInExclamationMark() {
assertTrue(astroboy.punch().endsWith("!"));
}
}

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Test Vibrator
@Singleton
public class Astroboy {

public void brushTeeth() {
vibrator.vibrate(
new long[]{0, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200,
50, 200, 50, 200, 50, 200, 50, }, -1);
}
...

}

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Test Code 2
public class Astroboy2Test {
...
@Test
public void brushingTeethShouldCausePhoneToVibrate() {
// get the astroboy instance
final Astroboy astroboy = RoboGuice.getInjector(context).getInstance(Astroboy.class);

// do the thing
astroboy.brushTeeth();

// verify that by doing the thing, vibratorMock.vibrate was called
verify(vibratorMock).vibrate(new long[]{0, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50},-1);
}
}

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Test Code 2
public class Astroboy2Test {
protected Application application = mock(Application.class, RETURNS_DEEP_STUBS);
protected Context context = mock(RoboActivity.class, RETURNS_DEEP_STUBS);
protected Vibrator vibratorMock = mock(Vibrator.class);
@Before
public void setup() {
// Override the default RoboGuice module
RoboGuice.setBaseApplicationInjector(application, RoboGuice.DEFAULT_STAGE,
Modules.override(RoboGuice.newDefaultRoboModule(application)).with(new MyTestModule()));
when(context.getApplicationContext()).thenReturn(application);
when(application.getApplicationContext()).thenReturn(application);
}
...
}

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Test Code 2
public class Astroboy2Test {
...
public class MyTestModule extends AbstractModule {
@Override
protected void configure() {
bind(Vibrator.class).toInstance(vibratorMock);
}
}
}

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Test Code 2
public class Astroboy2Test {
...
@After
public void teardown() {
// Don't forget to tear down our custom injector to avoid polluting other test classes
RoboGuice.util.reset();
}
}

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Log Framework

Log.d("TAG", "Sent say(" + something + ") command to Astroboy");
VS
Ln.d("Sent say(%s) command to Astroboy", something);

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Log Framework
public static int d(Object s1, Object[] args) {
...
}
Ln.d("Sent say(%s) command to Astroboy %s", something, “1”);
**it will automatically not log on a signed APK

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Short Workshop
Config
Build
Test
Deploy
Run
Debug
Maven - pom.xml #1
<properties>
<android.sdk.path>
C:Program Filesadt-bundle-windowssdk
</android.sdk.path>
</properties>

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Maven - pom.xml #1
<!-- REGULAR DEPENDENCIES -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<classifier>no_aop</classifier>
</dependency>
<dependency>
<groupId>org.roboguice</groupId>
<artifactId>roboguice</artifactId>
<version>3.0b-experimental</version>
</dependency>

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Maven - pom.xml #2
<!-- TEST DEPENDENCIES -->
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Maven - pom.xml #3
<!-- PROVIDED DEPENDENCIES -->
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>provided</scope>
</dependency>
<dependency> <!-- needed to prevent warnings in robolectric tests -->
<groupId>com.google.android.maps</groupId>
<artifactId>maps</artifactId>
<version>7_r1</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Maven - pom.xml #4
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<platform>18</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Maven - Command
mvn -DskipTests=true install
mvn test
mvn -DskipTests=true android:deploy
mvn -DskipTests=true android:run -Dandroid.run.debug=true

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
NETBEANS

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
Who uses RoboGuice?

@ COPYRIGHT 2013 NUBOAT IN WONDERLAND
QUESTION

THANK YOU
@ COPYRIGHT 2013 NUBOAT IN WONDERLAND

Más contenido relacionado

La actualidad más candente

Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Anton Arhipov
 
Contextual communications and why you should care - Droidcon DE
Contextual communications and why you should care - Droidcon DEContextual communications and why you should care - Droidcon DE
Contextual communications and why you should care - Droidcon DEMarcos Placona
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahNick Plante
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
Testable JavaScript: Application Architecture
Testable JavaScript:  Application ArchitectureTestable JavaScript:  Application Architecture
Testable JavaScript: Application ArchitectureMark Trostler
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMashleypuls
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMRafael Winterhalter
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokusHamletDRC
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistAnton Arhipov
 
Kotlinでテストコードを書く
Kotlinでテストコードを書くKotlinでテストコードを書く
Kotlinでテストコードを書くShoichi Matsuda
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracerrahulrevo
 
Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to WonderWO Community
 

La actualidad más candente (20)

Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
Java objects on steroids
Java objects on steroidsJava objects on steroids
Java objects on steroids
 
Contextual communications and why you should care - Droidcon DE
Contextual communications and why you should care - Droidcon DEContextual communications and why you should care - Droidcon DE
Contextual communications and why you should care - Droidcon DE
 
Annotation processing tool
Annotation processing toolAnnotation processing tool
Annotation processing tool
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
 
Testable JavaScript: Application Architecture
Testable JavaScript:  Application ArchitectureTestable JavaScript:  Application Architecture
Testable JavaScript: Application Architecture
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASM
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Mobile AR
Mobile ARMobile AR
Mobile AR
 
AST Transformations at JFokus
AST Transformations at JFokusAST Transformations at JFokus
AST Transformations at JFokus
 
JEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with JavassistJEEConf 2017 - Having fun with Javassist
JEEConf 2017 - Having fun with Javassist
 
Android basic 2 UI Design
Android basic 2 UI DesignAndroid basic 2 UI Design
Android basic 2 UI Design
 
Android basic 3 Dialogs
Android basic 3 DialogsAndroid basic 3 Dialogs
Android basic 3 Dialogs
 
Unit Testing in Kotlin
Unit Testing in KotlinUnit Testing in Kotlin
Unit Testing in Kotlin
 
Kotlinでテストコードを書く
Kotlinでテストコードを書くKotlinでテストコードを書く
Kotlinでテストコードを書く
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracer
 
Migrating existing Projects to Wonder
Migrating existing Projects to WonderMigrating existing Projects to Wonder
Migrating existing Projects to Wonder
 

Destacado (6)

Homeloan
HomeloanHomeloan
Homeloan
 
Meetup Big Data by THJUG
Meetup Big Data by THJUGMeetup Big Data by THJUG
Meetup Big Data by THJUG
 
Hadoop
HadoopHadoop
Hadoop
 
Modern Java Development
Modern Java DevelopmentModern Java Development
Modern Java Development
 
Cassandra - Distributed Data Store
Cassandra - Distributed Data StoreCassandra - Distributed Data Store
Cassandra - Distributed Data Store
 
Data Pipeline with Kafka
Data Pipeline with KafkaData Pipeline with Kafka
Data Pipeline with Kafka
 

Similar a Roboguice

Android Bootstrap
Android BootstrapAndroid Bootstrap
Android Bootstrapdonnfelker
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"IT Event
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"epamspb
 
Android testing
Android testingAndroid testing
Android testingSean Tsai
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Murat Yener
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean CodeGR8Conf
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureAlexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureC.T.Co
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaDILo Surabaya
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyJames Williams
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingAndres Almiray
 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIsDmitry Buzdin
 
Testing in android
Testing in androidTesting in android
Testing in androidjtrindade
 
New adventures in 3D
New adventures in 3DNew adventures in 3D
New adventures in 3DRob Bateman
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applicationsrohitnayak
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneDroidConTLV
 

Similar a Roboguice (20)

Android Bootstrap
Android BootstrapAndroid Bootstrap
Android Bootstrap
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
#ITsubbotnik Spring 2017: Roman Iovlev "Java edge in test automation"
 
Android testing
Android testingAndroid testing
Android testing
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
 
Testing in android
Testing in androidTesting in android
Testing in android
 
New adventures in 3D
New adventures in 3DNew adventures in 3D
New adventures in 3D
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
 

Más de Peerapat Asoktummarungsri (7)

ePassport eKYC for Financial
ePassport eKYC for FinancialePassport eKYC for Financial
ePassport eKYC for Financial
 
Security Deployment by CI/CD
Security Deployment by CI/CDSecurity Deployment by CI/CD
Security Deployment by CI/CD
 
Sonarqube
SonarqubeSonarqube
Sonarqube
 
Sonar
SonarSonar
Sonar
 
Lightweight javaEE with Guice
Lightweight javaEE with GuiceLightweight javaEE with Guice
Lightweight javaEE with Guice
 
Meet Django
Meet DjangoMeet Django
Meet Django
 
Easy java
Easy javaEasy java
Easy java
 

Último

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Último (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Roboguice

  • 1. RoboGuice DI & IoC framework for Android
  • 2. Me Software Engineer @ FICO Corp. Programmer @nuboat https://github.com/nuboat http://slideshare.net/nuboat/ @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 3. RoboGuice RoboGuice เป็ น framework สําหรั บทํา Dependency Injection บน Android, พั ฒนาจาก Google Guice library. ลั กษณะคล้ายกั บ Spring & EJB ของ JavaEE @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 4. Normal Style @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 5. RoboGuice Style @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 6. Requirements Java 6 or 7 Maven Android SDK (platform 18) Coffee & Beer (up to you) @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 7. Librarys RoboGuice v3.0b-experimental Google Guice v3.0 Roboelectric v1.0 Mockito v1.9.5 JUnit v4.8.2 @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 8. Advantage of RoboGuice Clean code Inherit Guice feature (Singleton, …) Automate Testing Log Framework @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 9. Clean Code RoboActivity not Activity @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 10. Inheriting from the RoboGuice RoboActivity RoboFragmentActivity RoboListActivity RoboLauncherActivity RoboExpandableListActivity RoboService RoboMapActivity RoboIntentService RoboPreferenceActivity RoboFragment RoboAccountAuthenticatorActivity RoboListFragment RoboActivityGroup RoboDialogFragment RoboTabActivity etc. @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 12. Singleton - Threadsafe @Singleton public class Astroboy { @Inject Application application; @Inject Vibrator vibrator; @Inject Random random; public void say(final String something) { // Make a Toast, using the current context as returned by the Context Provider Toast.makeText(application, "Astroboy says, "" + something + """, Toast.LENGTH_LONG).show(); } public void brushTeeth() { vibrator.vibrate(new long[]{0, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, }, -1); } public String punch() { final String expletives[] = new String[]{"POW!", "BANG!", "KERPOW!", "OOF!"}; return expletives[random.nextInt(expletives.length)]; } } @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 13. Test Random value @Singleton public class Astroboy { public String punch() { final String expletives[] = new String[]{"POW!", "BANG!", "KERPOW!", "OOF!"}; return expletives[random.nextInt(expletives.length)]; } ... } @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 14. Test Code 1 @RunWith(RobolectricTestRunner.class) public class Astroboy1Test { protected Context context = new RoboActivity(); protected Astroboy astroboy = RoboGuice.getInjector(context).getInstance(Astroboy.class); @Test public void stringShouldEndInExclamationMark() { assertTrue(astroboy.punch().endsWith("!")); } } @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 15. Test Vibrator @Singleton public class Astroboy { public void brushTeeth() { vibrator.vibrate( new long[]{0, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, }, -1); } ... } @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 16. Test Code 2 public class Astroboy2Test { ... @Test public void brushingTeethShouldCausePhoneToVibrate() { // get the astroboy instance final Astroboy astroboy = RoboGuice.getInjector(context).getInstance(Astroboy.class); // do the thing astroboy.brushTeeth(); // verify that by doing the thing, vibratorMock.vibrate was called verify(vibratorMock).vibrate(new long[]{0, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50, 200, 50},-1); } } @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 17. Test Code 2 public class Astroboy2Test { protected Application application = mock(Application.class, RETURNS_DEEP_STUBS); protected Context context = mock(RoboActivity.class, RETURNS_DEEP_STUBS); protected Vibrator vibratorMock = mock(Vibrator.class); @Before public void setup() { // Override the default RoboGuice module RoboGuice.setBaseApplicationInjector(application, RoboGuice.DEFAULT_STAGE, Modules.override(RoboGuice.newDefaultRoboModule(application)).with(new MyTestModule())); when(context.getApplicationContext()).thenReturn(application); when(application.getApplicationContext()).thenReturn(application); } ... } @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 18. Test Code 2 public class Astroboy2Test { ... public class MyTestModule extends AbstractModule { @Override protected void configure() { bind(Vibrator.class).toInstance(vibratorMock); } } } @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 19. Test Code 2 public class Astroboy2Test { ... @After public void teardown() { // Don't forget to tear down our custom injector to avoid polluting other test classes RoboGuice.util.reset(); } } @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 20. Log Framework Log.d("TAG", "Sent say(" + something + ") command to Astroboy"); VS Ln.d("Sent say(%s) command to Astroboy", something); @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 21. Log Framework public static int d(Object s1, Object[] args) { ... } Ln.d("Sent say(%s) command to Astroboy %s", something, “1”); **it will automatically not log on a signed APK @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 23. Maven - pom.xml #1 <properties> <android.sdk.path> C:Program Filesadt-bundle-windowssdk </android.sdk.path> </properties> @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 24. Maven - pom.xml #1 <!-- REGULAR DEPENDENCIES --> <dependency> <groupId>com.google.inject</groupId> <artifactId>guice</artifactId> <version>3.0</version> <classifier>no_aop</classifier> </dependency> <dependency> <groupId>org.roboguice</groupId> <artifactId>roboguice</artifactId> <version>3.0b-experimental</version> </dependency> @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 25. Maven - pom.xml #2 <!-- TEST DEPENDENCIES --> <dependency> <groupId>com.pivotallabs</groupId> <artifactId>robolectric</artifactId> <version>1.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>1.9.5</version> <scope>test</scope> </dependency> @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 26. Maven - pom.xml #3 <!-- PROVIDED DEPENDENCIES --> <dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>4.2.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.2</version> <scope>provided</scope> </dependency> <dependency> <!-- needed to prevent warnings in robolectric tests --> <groupId>com.google.android.maps</groupId> <artifactId>maps</artifactId> <version>7_r1</version> <scope>provided</scope> <optional>true</optional> </dependency> @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 27. Maven - pom.xml #4 <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> <version>3.7.0</version> <configuration> <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile> <assetsDirectory>${project.basedir}/assets</assetsDirectory> <resourceDirectory>${project.basedir}/res</resourceDirectory> <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory> <sdk> <platform>18</platform> </sdk> <undeployBeforeDeploy>true</undeployBeforeDeploy> </configuration> <extensions>true</extensions> </plugin> @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 28. Maven - Command mvn -DskipTests=true install mvn test mvn -DskipTests=true android:deploy mvn -DskipTests=true android:run -Dandroid.run.debug=true @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 29. NETBEANS @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 30. Who uses RoboGuice? @ COPYRIGHT 2013 NUBOAT IN WONDERLAND
  • 31. QUESTION THANK YOU @ COPYRIGHT 2013 NUBOAT IN WONDERLAND