Fritter Factory


Source link: https://github.com/equinox-one/fritterfactory

Fritter Factory

Library to automatically populate models, to be used in automatic tests or user made tests.

When performing automatic test we need to create models constantly. Moreover when using hand made test, we may need to populate an application with fake data. Fritter Factory has been developed to solve this problems.

Android friendly

Fritter Factory is Android Friendly: it does not use any reflection methods not implemented in the Android libraries. Therefore, it can be used in Android applications without any problem.

Show me an example

Let's imagine that we have the following model

public class Person {

  String name;
  String surname;
  int age;
  Adress adress;
  String description;
  Category category;
  String image; 
}

We can create a person with all the attributes set with the following:

FritterFactory fritterFactory = new FritterFactory();
 List<Person> persons = fritterFactory.buildList(Person.class, 3);

Show me a better example

That's not all! FritterFactory allows the generated models to be configurable. In this example we will use Symbols but its not mandatory:

 /** 
  * Print 3 persons, using specific providers defined by a mold. 
  */
  public void sampleWithMolds(){

FritterFactory fritterFactory = createFactoryWithMolds();

List<Person> persons = fritterFactory.buildList(Person.class, 3);

System.out.println(persons);

  
}

/** 
  * Creates a FritterFactory with defined providers for Person and Adress. 
  * @return 
  */
  public FritterFactory createFactoryWithMolds(){

FritterFactory fritterFactory = new FritterFactory();

fritterFactory.addProvider(Person.class, createPersonProvider(fritterFactory));

fritterFactory.addProvider(Adress.class, createAdressProvider(fritterFactory));

return fritterFactory;
  
}

public Provider<Person> createPersonProvider(FritterFactory fritterFactory){

MapMold personMold = new MapMold();

personMold.put(PersonSymbols.NAME, new FirstNameProvider());

personMold.put(PersonSymbols.SURNAME, new FirstNameProvider());

personMold.put(PersonSymbols.AGE, new IntegerProvider(0,110));

personMold.put(PersonSymbols.DESCRIPTION, new WordProvider(50, 100));

personMold.put(PersonSymbols.IMAGE, new PersonImageProvider());

return new ModelProvider<Person>(fritterFactory, Person.class, personMold);

  
}

public Provider<Adress> createAdressProvider(FritterFactory fritterFactory){

MapMold adressMold = new MapMold();

adressMold.put(AdressSymbols.STREET, new WordProvider(1, 3));

adressMold.put(AdressSymbols.CITY, new CityProvider());

adressMold.put(AdressSymbols.COUNTRY, new CountryProvider());

return new ModelProvider<Adress>(fritterFactory, Adress.class, adressMold);

  
}

Get full Example

You can download the full example at github.

Which types can be automatically populated.

By default, Fritter Factory is created using the DefaultProviderFactory. This allows to create the following random values:

  • String.class
  • Integer.class
  • int.class
  • Long.class
  • long.class
  • Double.class
  • double.class
  • Float.class
  • float.class
  • Boolean.class
  • boolean.class
  • Date.class
  • Calendar.class

Adding providers

It can also create complex models that use this sub types. However we may need to create our own providers in some cases. As an example, lets imagine that we use Joda time classes and we have a model that uses LocalDate. We will need to create a provider for this type like the following:

public class LocalDateProvider implements Provider<LocalDate> {

  Random random = new RandomFactory().get();

@Override
  public LocalDate get() {

return new LocalDate(random.nextLong());

  
}
 
}

and add it to the Fritter Factory

fritterFactory.addProvider(LocalDate.class, new LocalDateProvider());

Default constructor required

One last thing. To create new instances of your classes, FritterFactory needs to find a default constructor (one with no parameters). This constructor can be private (if desired), but must exist.

Download

Grab via Gradle:

repositories {
 jcenter() 
}
  compile 'one.equinox.fritterfactory:fritterfactory:+'

or via Maven:

<repository>
<id>jcenter</id>
<url>http://jcenter.bintray.com</url> </repository>  <dependency>
  <groupId>one.equinox.fritterfactory</groupId>
  <artifactId>fritterfactory</artifactId>
  <version>+</version> </dependency>

What's next

Some ideas on how to improve this library

  • Create more default providers for other types.
  • Use annotation processing to create mold classes instead of using Symbols.

License

 Copyright 2016 Equinox.one
Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and  limitations under the License. 

Resources

Quick action dialog fragment.

A very simple currency converter for Android.

ClassyShark is a handy browser for Android executables. It has clients for both Android (apk) and Desktop (jar). With ClassyShark you can open APK/Zip/Class/Jar files and analyze their contents.

It is a simple MVP demo which shows how to pick photos.

A custom TextView, when pinch in out gesture used, then it resizes text size.

This library analyses a best crop position and size by calculating some features (edge, skin tone, staturation and face).

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes