Android Ant Proposal
We just finished submitting a proposal to the adt-dev Google Group. Here is a link to the new proposal. The goal of the proposal is to get a set of standard Ant tasks developed for Android.
We would appreciate some feedback on this proposal. Let us know if you would like to help or have ideas.
Mocking Frameworks Considered Harmful
I’ve been on several projects where developers use Java mocking frameworks. The most popular of these frameworks is called Mockito. I’m pretty open to giving new technology the benefit of the doubt. I used it for several months and found reasons to consider mocking frameworks harmful. I constantly get asked why I don’t use them by other developers. I always say that one day I’ll write a blog article on the subject. Here it is.
Here are the reasons I consider mocking frameworks harmful:
1. When you need to use mock objects , you are saying that you are unable to use standard unit testing on your code.
2. The tests you develop with mocking frameworks are tightly coupled to the internals of the code.
3. The code you test with mocking frameworks is hard to refactor.
1. When you need to use mock objects, you are saying that you are unable to use standard unit testing on your code.
I’ve seen systems where testing using mock objects was the only option. This is usually a sign there is a major design problem in the system. The most common cause is too much coupling in the code base. This can mean too much coupling in the domain layer or between layers (e.g. domain and infrastructure). Or, classes have references to “god” objects (i.e. objects that have too much responsibility).
The most important part of Object Oriented Programming is build a solid domain model; it should be independent of other layers. See Eric Evans diagram for a good example of domain-driven-design architecture. This domain model needs to limit the number of points where it interacts with infrastructure services. I’m going to use the example of a database infrastructure service. The domain model should have an interface database through some type of “repository” object or facade. A common use case for mocking is to test classes that interface with a database. This becomes a major obstacle in systems where JDBC objects are sprinkled around in the domain layer. These objects need to be bundled in a cohesive class or package to reduce the coupling between the domain layer and infrastructure layers. The repository objects that communicate with the database need to be interfaces. This allows you to change database technologies later in the project because all the JDBC code is in one area. When these repository interfaces are trivial, you can even do things like create in-memory concrete instances of repositories for testing.
You might say, “Okay that’s great, now my database calls are all in the same class. But I still need to unit test them!” Here’s the deal my young apprentice. Testing interactions between larger systems/components is not unit testing. It’s called integration testing. That’s why it’s important to have a suite of integration tests to exercise all the major functions of your system. Your integration tests should be run regularly during development. Consider using a Linux cron job with automatic email reporting. When you have a hammer, every problem looks like a nail. Remember that you have a toolbox. One of my favorite tricks in integration testing is using Python scripts to call interfaces and aggregate results.
2. The tests you develop with mocking frameworks are tightly coupled to the internals of the code.
The first point wasn’t enough to convince you that mocking frameworks are considered bad practice, eh? So you went to work the next day and create the class called “SuperAwesomeHelperUtility”. Yes, it’s more or less a god class that knows everything about sandwiches, email systems, and databases. But you don’t care because your mocking framework will help you test this utility. Please don’t attempt this type of coding at home or work.

Here is one of your unit tests:
@Test public void testMakeTurkeySandwichEmailTomAndStoreSandwichData() { Connection mockConnection = mock(Connection.class); EmailServer mockEmailServer = mock(EmailServer.class); SandwichMaker mockSandwichMaker = mock(SandwichMaker.class); SuperAwesomeHelperUtility utility = new SuperAwesomeHelperUtility(mockConnection, emailServer, sandwichMaker); utility.makeSandwichEmailFriendAndStoreSandwichDataInDatabase("tom@tomiscool.com", "turkey", "turkeydb"); verify(mockConnection).executeUpdate("insert into sandwich values (\"turkey\")"); verify(mockSandwichMaker).createTurkeySandwich(); verify(mockEmailServer).email("tom@tomiscool.com"); }
First, the test above isn’t a complete unit test. It’s just an example of the types of calls that cause tight coupling between code and unit tests. In the example above, the internal calls in the method “makeSandwichEmailFriendAndStoreSandwichDataInDatabase” have been exposed by the mock objects passed in the constructor of the “utility” instance. The concept of encapsulation is being broken by verifying the calls to external components are made.
Again, this is an example of bad design. But this is the trap that mock framework users fall into. It becomes their crutch when implementations are hard to unit test. Soon the practice becomes common in a group because it somewhat solves the problem. This type of viral malpractice needs to be identified early and stopped.
3. The code you test with mocking frameworks is hard to refactor.
Have you ever tried refactoring code that has all the calls to other components mock tested? It’s impossible. Especially when there are thousands of verify calls to other components in a unit test class. That doesn’t sound very agile, does it? You might have to throw away the entire unit test and start over if you decided to refactor the “Connection”, “EmailServer”, or “SandwichMaker” classes or method signatures found in item 2 above.
Everyone knows how important unit testing is during development. The point of unit testing is to test the functionality of one unit of code. That usually means testing at the method level. In my experience, good code can be easily tested at the unit level because it doesn’t depend on lots of other services for testing. Here’s another example. Say you want a function that tests adding two numbers together:
// adds two numbers together and returns the result public int add(int x, int y) { ... }
That’s as simple as it gets in programming. And that’s the whole idea! You want to write simple methods in Object Oriented Programming. You also want to reduce dependencies between classes. Your class for adding two numbers together should not have a dependency on the “SuperAwesomeHelperUtility”. If it does and you need to mock it for testing, you’re doing something wrong.
Microtransaction Library Uploaded
I finally finished enough of the microtransaction library I mentioned during our last podcast and posted it on our site. I made the license open source so you can use it in your own projects. I wrote some documentation on how to use it. Also, I marked it as beta since it hasn’t been fully tested and integrated into a real application yet. This project has a lot of potential. It greatly simplifies the life of developers who want to use in-app billing.
Here is a link to the new library:
http://www.disgruntledrats.com/?page_id=589
Disgruntled Rats Podcast for September 11, 2011
Download Podcast
Download the Podcast for September 11, 2011
Show Notes
Introduction
Michael Boldischar
Sean Godinez
Brian Morgan
Computer Graphics
Cloth Simulation Algorithms
http://www.geeks3d.com/20110825/opencloth-a-collection-of-cloth-simulation-algorithms/
WebGL Raytracing Water Simulation
http://www.geeks3d.com/20110818/raytraced-water-simulation-webgl/
http://madebyevan.com/webgl-water/
http://rastergrid.com/blog/2011/08/an-introduction-to-opengl-4-2/
Android
Google Buys Motorola Mobility
http://googleblog.blogspot.com/2011/08/supercharging-android-google-to-acquire.html
Amazon Kindle Rumors
http://gizmodo.com/5837061/this-is-amazons-kindle-tablet
Android Steals 20% of iPad Tablet Market
http://www.bgr.com/2011/08/12/android-steals-20-of-tablet-market-from-ipad-over-past-year/
Gaming
Tactile Feedback from Disney
http://www.sciencedaily.com/releases/2011/08/110808152421.htm
Battlefield 3: Focusing on Innovation
http://www.ign.com/videos/2011/09/04/battlefield-3-focussing-on-innovation?objectid=14209865
http://www.slideshare.net/DICEStudio/five-rendering-ideas-from-battlefield-3-need-for-speed-the-run
Minecraft and Steam
http://multiplayerblog.mtv.com/2011/08/30/minecraft-steam/
Discussion Topic: Using content delivery services. Good idea for new games? Build or buy?
Other/Random
George Clooney Suggests Matt Damon For Presidency
Spotlight
Microtransactions/In App Billing in Android
http://developer.android.com/guide/market/billing/index.html
Conclusion
We are accepting short audio questions to play during one of our recorded episodes. If you would like your question played on our show, email an audio clip to disgruntledrats@gmail.com
You can find show notes on our website: www.disgruntledrats.com
Friend us on Facebook for your chance to win a Disgruntled Rats t-shirt
If we made a mistake or you have news to share, or want a product reviewed, email us at disgruntledrats@gmail.com
Game Development in Android
Thanks to everyone who attended our session on game development in Android yesterday. Sean, Brian and I all had a great time and enjoyed the questions and interactive discussions. If you have any other questions for us, send us an email at disgruntledrats@gmail.com.
Here is a copy of the presentation we gave. Also, the Java User Group website should be posting a recording of our event sometime in the future.
Happy coding!
New Android Examples Added
In preparation for the Twin Cities Java User Group Presentation on August 9th, 2011, the Disgruntled Rats have added new Android example projects to their website. Check out the following link for more information: http://www.disgruntledrats.com/?page_id=545
We will continue adding examples and content to our website that is useful to developers as time permits.
Cheers and happy coding!
The Quick and Dirty to OpenGL ES 2.0 on Android
This is a short article for those familiar with OpenGL's programmable pipeline and are interested in using the OpengGL ES 2.0 API for Android development. To use the OpenGL ES API in an Android environment you have to setup a GLSurfaceView object, override the GLSurfaceView.Renderer, and attach the renderer to the surfaceview. Additionally, you could extend GLSurfaceView to capture touchscreen events by overriding onTrackballEvent() and onTouchEvent(). Step 1) Check that OpenGL ES 2.0 is supported and attach your renderer.
import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.content.pm.ConfigurationInfo; import android.opengl.GLSurfaceView; import android.os.Bundle; public class MyOpenGLApp extends Activity { private GLSurfaceView mGLSurfaceView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mGLSurfaceView = new GLSurfaceView(this); ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); ConfigurationInfo info = am.getDeviceConfigurationInfo(); if(info.reqGlEsVersion >= 0x20000) { mGLSurfaceView.setEGLContextClientVersion(2); mGLSurfaceView.setRenderer(new MyOpenGLAppRenderer(this)); } else { //Buy a new phone finish(); } setContententView(mGLSurfaceView); } @Override protected void onResume() { super.onResume(); mGLSurfaceView.onResume(); //Do additional stuff to unpause your game/app } @Override protected void onPause() { super.onPause(); mGLSurfaceView.onPause(); //Do additional stuff to pause your game/app } }
Step 2) Setup your OpenGL Renderer
a. Override onSurfaceCreated
b. Override onDrawFrame
c. Override onSurfaceChanged
import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.opengl.GLSurfaceView; import android.opengl.GLES20; public class MyOpenGLAppRenderer implements GLSurfaceView.Renderer { public MyOpenGLAppRenderer(Context context) {} public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { //Initialization -> Steps 3, 4, and 5 } public void onDrawFrame(GL10 glUnused) { //Update the graphics, bind resources, and render -> Steps 6 and 7 } public void onSurfaceChanged(GL10 glUnused, int width, int height) { //Adjust your camera/rendering parameters or just look funny } }
Step 3) Initialize your shader program
a. Create, load, and compile the vertex and fragment shaders
i. glCreateShader(shader_type) // => GL_VERTEX_SHADER / GL_FRAGMENT_SHADER
ii. glShaderSource(shader_reference, shader_source_code);
iii. glCompileShader(shader_reference);
b. Create the shader program and attach the vertex and fragment shaders
i. glCreateProgram();
ii. glAttachShader(program_reference, vertex_shader_reference);
iii. glAttachShader(program_reference, fragment_shader_reference);
c. Link the program and check for errors
i. glLinkProgram(program_reference);
ii. glGetProgramiv(program_reference, GL_LINK_STATUS, results, 0);
Step 4) Request the locations of specific variables within the shader program
a. Uniform Locations
i. glGetUniformLocation(program_reference, "uniform_name_goes_here");
b. Attribute Locations (can also be mapped during vertex buffer binding)
i. glGetAttribLocation(program_reference, "attribute_name_goes_here")
Step 5) Create and Load Vertex Buffer Objects (it’s a little different if you are not using VBOs)
a. Create Vertex and Index Buffers
glGenBuffers(number_of_desired_buffers, returned_buffer_IDs, 0)
b. Bind Vertex Buffer
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_id)
c. Load Vertex data into buffer
glBufferData(GL_ARRAY_BUFFER, size_in_bytes, vertex_data, GL_STATIC_DRAW);
d. Bind Index Buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_id)
e. Load Index data into buffer
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size_in_bytes, index_data, GL_STATIC_DRAW);
Step 6) Rendering Preparation
a. Use the program shader
i. glUseProgram(program_reference)
b. Map each Vertex Attribute to an index (ex: position attribute below)
i. glEnableVertexAttribArray(VERTEX_POS_INDEX)
ii. glVertexAttribPointer(VERTEX_POS_INDEX, VERTEX_POS_SIZE, GL_FLOAT, false,
VERTEX_SIZE_IN_BYTES, offset_in_vertex_structure)
c. Bind each Attribute Index to its respective attribute location in the Vertex Shader
i. glBindAttribLocation(program_reference, VERTEX_POS_INDEX, “a_position”)
d. Send uniform data like the model-view projection matrix to the GPU
i. glUniformMatrix4fv(mvp_location, 1, false, mvpMatrix.getAsFloatBuffer());
Step 7) Render
a. glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, offset)
Step 8) The quick and dirty clean up calls for you neat freaks out there
a. glDeleteBuffers(number_of_buffers, buffer_IDs)
b. glDeleteShader(shader_reference)
c. glDeleteProgram(program_reference)
Summary
Step 1 sets up your activity class, queries EGL (the ‘glue’ between OpenGL and the OS window) for OpenGL ES 2.0 compatability and attaches your renderer.
Step 2 sets up your renderer class allowing you to handle initialization, rendering frames, and handling surface size changes.
Step 3 gets your shaders down to the GPU as binary instructions.
Step 4 gets the ‘addresses’ of variables in your shader program so that you can push data into them from the client side.
Step 5 builds your vertex buffer objects on the GPU. These VBOs hold data such as vertex positions, normals, colors, and texture coordinates.
Step 6 maps the data in your vertex structures to attribute variables in your vertex shader, and also pushes data (like the model-view matrix) down to your shader’s uniform variables.
Step 7 renders the attribute arrays we mapped out using glVertexAttribPointer in Step 6.
Finally, Step 8 does some clean up.
For more detailed information in audio form check out some of our podcast spotlights. I go through the OpenGL ES 2.0 pipeline in our March 20th, 2011 podcast and take a deep dive into bump mapping, parallax mapping, and relief mapping in our July 10th, 2011 podcast.
If you are looking for a good book on this topic you can’t go wrong with the OpenGL ES 2.0 Programming Guide by Aaftab Munshi, Dan Ginsburg, and Dave Shreiner. The book’s code examples are in C, but it’s a fairly straight forward mapping to Android’s GLES20 class. There are also some Android examples on the book’s website. They can be pulled down via svn from here: http://opengles-book-samples.googlecode.com/svn/trunk/Android/
Feel free to post any questions or comments.
DGR will be presenting at the Twin Cities Java User Group on August 8th, 2011
The Disgruntled Rats are presenting information on game development for the Android platform. We have been working on building an Android graphics engine for over a year now and have interesting lessons to share. Everything from basic game components (sound, sprites, events) to complex calculations (AI, transformations, and physics).
Also included in the presentation will be information on setting up an Android OpenGL project and many examples you will be able to download and try on your own. Finally, we will discuss strategies for marketing and selling games. Developers are welcome to chime in with their own Android Market experiences.
Date:
Monday, August 08, 2011
Time:
Social time starts by 5:30pm and the presentation starts promptly at 6:00pm, typically lasting for an hour to an hour and a half.
Address:
1020 Discovery Road, Suite 145
Eagan, MN 55121
USA
Speakers:
Michael Boldischar, Brian Morgan, Sean Godinez
Disgruntled Rats Podcast for July 10, 2011
Download Podcast
Download the Podcast for July 10, 2011
Show Notes
Introduction
The Crew
Michael Boldischar
Sean Godinez
Brian Morgan
Computer Graphics
1. Neo Axis New Graphics Mobile Engines Released
2. Neuro-Systems Augmented Reality
Other News
1. Judge rules against Google in Street View ‘Wi-Spy’ lawsuit
2. Massive botnet ‘indestructible,’ say researchers
4.5M-strong botnet ‘most sophisticated threat today’ to Windows PCs
http://www.computerworld.com/s/article/9218034/Massive_botnet_indestructible_say_researchers
Android
1. Google Maps = offline mode?
http://www.engadget.com/2011/06/08/google-maps-navigation-to-go-offline-this-summer-garmin-and-tom/
2. Google+ now available on Android Market
https://market.android.com/details?id=com.google.android.apps.plus
3. HTC Evo 3D Released
3D Modeling
1. Mobile Virtual World With a Flexible Virtual Reality System
http://www.sciencedaily.com/releases/2011/05/110531135711.htm
2. Valve Source SDK Released
http://www.rockpapershotgun.com/2011/06/30/not-only-but-also-source-sdk-to-be-free/
Gaming
1. Heroes Of Might And Magic 3 Comes To Android
2. Kinder, Gentler Video Games May Actually Be Good for Players
http://www.sciencedaily.com/releases/2011/06/110606113403.htm
3. Team Fortress 2 To Become Free Game
http://www.develop-online.net/news/38103/Team-Fortress-2-becomes-free-forever
SpotLight
Presenter: Sean Godinez
Bump Mapping
Parallax Mapping
Relief Mapping
Conclusion
Look for us at the Twin Cities Java User Group Convention in August, 8th 2011!
As always, go to www.disgruntledrats.com and Like us on facebook to be entered in a monthly drawing for a free DGR T-shirt. They are awesome!
Disgruntled Rats Podcast for May 23, 2011
Show Notes
Introduction
Michael Boldischar
Sean Godinez
Brian Morgan
Special Guest: John Carlson
Computer Graphics
1. Survey of Game Developer Salaries
http://www.cgw.com/Press-Center/News/2011/2010-Game-Developer-Salary-Survey-Reports-Mainst.aspx
PhysX 3.X Roadmap
http://www.geeks3d.com/20110511/physx-3-x-roadmap-details-linux-version/
2. Intel OpenCL SDK 1.1
http://www.geeks3d.com/20110510/intel-opencl-1-1-sdk-beta-version/
3. GPU To Accelerate the Linux Kernel
http://www.geeks3d.com/20110509/kgpu-when-the-gpu-is-used-to-accelerate-the-linux-kernel/
Android
1. Google blocks rooted Android phones
http://www.androidcentral.com/google-movies-blocked-rooted-devices
2. Netflix App Comes to Android
http://www.engadget.com/2011/05/12/netflix-releases-android-app-for-select-htc-phones-samsung-nexu/
3. Hello Verizon, Goodbye Unlimited Data
http://www.pcworld.com/article/228256/verizon_say_so_long_to_unlimited_data.html
4. Evo 3D Preorders
http://www.tgdaily.com/mobility-brief/56049-radio-shack-opens-up-htc-evo-3d-pre-orders
http://www.tgdaily.com/mobility-brief/55711-best-buy-opens-up-evo-3d-pre-orders
5. Ice Cream Sandwich Details
3D Modeling
1. Walt Disney Open Sources Two Software Programs
http://www.cgw.com/Press-Center/News/2011/Walt-Disney-Animation-Studios-Announces-Open-Sou.aspx
http://www.disneyanimation.com/technology/opensource.html
Gaming
1. Free Xbox with Student Laptop Purchase
http://news.cnet.com/8301-13506_3-20064263-17.html?tag=mncol;title
2. Arrrghhh! Stop Virtual Pirates!
http://news.cnet.com/8301-13506_3-20061821-17.html?tag=mncol;title
http://mmowgli.nps.edu/mmowgli
3. XPeria Play Coming Next Week
http://www.tgdaily.com/mobility-brief/56002-xperia-play-finally-coming-to-us-next-week
4. Sony, Sony, Sony = (
http://en.wikipedia.org/wiki/George_Hotz
http://ps3movies.ign.com/ps3/document/article/108/1086720/gov.uscourts.cand.226894.1.0.pdf
http://www.tomshardware.com/news/PlayStation-Linux-PS3-Xbox-Xbox-360,10311.html
http://www.zdnet.com/blog/gamification/security-expert-testifies-sony-servers-went-unpatched/374
http://www.tomsguide.com/us/credit-card-phishing-Sony-Server-PSN-Breach,news-11271.html
http://www.tomshardware.com/news/PlayStation-Network-PSN-PSN-premium-XBL-Xbox-Live,10457.html
http://www.gamasutra.com/view/news/34766/Hacker_Attacks_Against_Sony_Continue.php
Other
1. Adding Reflection to C++
http://www.gamasutra.com/view/feature/6379/sponsored_feature_behind_the_.php
Spotlight
John Carlson, Breakwater Inc.
Conclusion
We are accepting short audio questions to play during one of our recorded episodes. If you would like your question played on our show, email an audio clip to disgruntledrats@gmail.com
You can find show notes on our website: www.disgruntledrats.com
Friend us on Facebook for your chance to win a Disgruntled Rats t-shirt
If we made a mistake or you have news to share, or want a product reviewed, email us at disgruntledrats@gmail.com

March 17th, 2012
Posted in





