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
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingAndres 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
 
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
 
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
 

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

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Último (20)

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

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