SlideShare a Scribd company logo
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

More Related Content

What's hot

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
 
Java objects on steroids
Java objects on steroidsJava objects on steroids
Java objects on steroids
Romain Rochegude
 
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
Marcos Placona
 
Annotation processing tool
Annotation processing toolAnnotation processing tool
Annotation processing tool
Andrzej Ludwikowski
 
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
Nick 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 reloading
Anton Arhipov
 
Testable JavaScript: Application Architecture
Testable JavaScript:  Application ArchitectureTestable JavaScript:  Application Architecture
Testable JavaScript: Application Architecture
Mark Trostler
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASM
ashleypuls
 
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 JVM
Rafael Winterhalter
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
Mobile AR
Mobile ARMobile AR
Mobile AR
Seyed Jafari
 
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 Javassist
Anton Arhipov
 
Android basic 2 UI Design
Android basic 2 UI DesignAndroid basic 2 UI Design
Android basic 2 UI Design
Eakapong Kattiya
 
Android basic 3 Dialogs
Android basic 3 DialogsAndroid basic 3 Dialogs
Android basic 3 Dialogs
Eakapong Kattiya
 
Unit Testing in Kotlin
Unit Testing in KotlinUnit Testing in Kotlin
Unit Testing in Kotlin
Egor Andreevich
 
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
 

What's hot (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
 

Viewers also liked

Meetup Big Data by THJUG
Meetup Big Data by THJUGMeetup Big Data by THJUG
Meetup Big Data by THJUG
Peerapat Asoktummarungsri
 
Modern Java Development
Modern Java DevelopmentModern Java Development
Modern Java Development
Peerapat Asoktummarungsri
 
Cassandra - Distributed Data Store
Cassandra - Distributed Data StoreCassandra - Distributed Data Store
Cassandra - Distributed Data Store
Peerapat Asoktummarungsri
 
Data Pipeline with Kafka
Data Pipeline with KafkaData Pipeline with Kafka
Data Pipeline with Kafka
Peerapat Asoktummarungsri
 

Viewers also liked (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 to Roboguice

Android Bootstrap
Android BootstrapAndroid Bootstrap
Android Bootstrap
donnfelker
 
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 Compiler
Garth 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 testing
Sean 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'15
Murat Yener
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
GR8Conf
 
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
Thierry Wasylczenko
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
Paul King
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureC.T.Co
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureAlexey Buzdin
 
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
DILo Surabaya
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Andres Almiray
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyJames Williams
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jiayun Zhou
 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIsDmitry Buzdin
 
Testing in android
Testing in androidTesting in android
Testing in android
jtrindade
 
New adventures in 3D
New adventures in 3DNew adventures in 3D
New adventures in 3D
Rob 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 Applications
rohitnayak
 
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
DroidConTLV
 

Similar to 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
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
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
 

More from Peerapat Asoktummarungsri

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

More from 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
 

Recently uploaded

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 

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