SlideShare uma empresa Scribd logo
1 de 31
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque (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
 

Semelhante 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
 

Semelhante 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
 

Mais 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

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 

Último (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

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