Randomizer


Source link: https://github.com/android-Infoedge/randomizer

#Randomizer

Annotation based library which is used to generate random data. This library uses reflection to parse annotations set on fields of model classes.This library makes it super easy to generate unlimited random data for proper testing of your application.it requires minimal code changes and no boilerplate code to generate random data. You just have to specify annotations on fields.

Features

  • Primitive and Non Primitive fields can be annotated.
  • Reference type of some other class can be annotated.
  • Built in data is more than enough for all random data needs.
  • Custom data generator can be set for random data type for field.
  • Built in data generators can be reused to create custom data generator.

Supported Annotations

  • @AppBundleID
  • @AppName
  • @AppVersion
  • @Avatar
  • @BooleanValue
  • @City
  • @CollectionDescriptor
  • @ColorName
  • @CompanyName
  • @Country
  • @CountryCode
  • @CreditCardNumber
  • @CreditCardType
  • @Currency
  • @CurrencyCode
  • @CustomList
  • @DateValue
  • @DomainName
  • @DummyImageUrl
  • @Email
  • @Encrypt
  • @FileName
  • @FirstName
  • @Frequency
  • @FullName
  • @Gender
  • @Guid
  • @HexColor
  • @IpAddressV4
  • @IpAddressV6
  • @Isbn
  • @JobTitle
  • @Language
  • @LastName
  • @Latitude
  • @LinkedInSkill
  • @Longitude
  • @MacAddress
  • @Mapping
  • @MD5
  • @MimeType
  • @Money
  • @Number
  • @Paragraphs
  • @Phone
  • @Race
  • @RowNumber
  • @Sentences
  • @Sequence
  • @SHA1
  • @SHA256
  • @ShirtSize
  • @SSN
  • @State
  • @StreetAddress
  • @Suffix
  • @Time
  • @TimeZone
  • @Title
  • @TopLevelDomain
  • @URL
  • @Username
  • @Words

Some of above annotations may have options to customize its behaviour.

@DateValue( from = "01 Jan 2001",to = "31 Dec 2002" , customFormat = "dd MMM yyyy") String dateOfBirth;  @Number(min = 20,max = 30,decimals = 0) int age;

#Code Examples

Single class

public class Person {

@FullName
  String name;

@DateValue( from = "01 Jan 2001",to = "31 Dec 2002" , customFormat = "dd MMM yyyy")
  String dateOfBirth;

@Number(min = 20,max = 30,decimals = 0)
  int age;

@Avatar(width = 100,height = 100,format = Avatar.Format.PNG)
  String profileAvatar;

@Phone(country = Phone.Country.INDIA)
  @CollectionDescriptor(min = 1,max = 3)
  List<String> phones; 
}

class Using Class (one to one)

public class Student {

@FullName
  public String name;

@ReferenceRecord(clazz = Address.class)
  public Address address; 
}
@ReferencedRecord public class Address {

@StreetAddress
  public String streetAddress;

@State
  public String state; 
}

Please note @ReferencedRecord at Address class.This is required.

class using class (one to many)

public class Student {

@FullName
  public String name;

@ReferenceRecord(clazz = Address.class)
  @CollectionDescriptor(min = 1,max = 2)
  public List<Address> address;

}
@ReferencedRecord public class Address {

@StreetAddress
  public String streetAddress;

@State
  public String state;  
}

Using custom generator

//Please note that it extends GenerationRule public class CustomCreditCardNumberGenerator extends GenerationRule<CreditCardNumber,String> {

public CustomCreditCardNumberGenerator(CreditCardNumber annotation, ProviderFactory providerFactory) {

super(annotation, providerFactory);

  
}

//Will be called automatically to generate random data from source
  @Override
  public String generate() {

return CARD_NUMBERS[getRandom().nextInt(CARD_NUMBERS.length)];
  
}

//Provide your own data
  private final String[] CARD_NUMBERS = {
"0111-0666-9888-7666","0777-9453-5672-7765"
}
; 
}
public class Person {

@CreditCardNumber
  @CustomGenerator(generator = CustomCreditCardNumberGenerator.class)
  public String creditCardNumber; 
}

Using existing Generator with Custom Generator

//Please note that it extends DelegateGenerationRule rather than simple GenerationRule public class CustomEmailGenerator extends DelegateGenerationRule<Email,String> {

public CustomEmailGenerator(Email annotation, ProviderFactory providerFactory, GenerationRule<Email, String> mCoreGenerator) {

super(annotation, providerFactory, mCoreGenerator);

  
}

@Override
  public String generate() {

return getCoreRandomData().toUpperCase();

  
}
 
}
 
public class Person {

@Email
  @CustomGenerator(generator = CustomEmailGenerator.class,delegate = EmailGenerator.class)
  @CollectionDescriptor(min = 2,max = 5)
  public List<String> emails; 
}

Generator name follows convention Annotation name followed by Generator eg. Annotation = @Email Generator = EmailGenerator

How to generate records ?

Generator<Person> generator = new Generator<>(Person.class);
 List<Person> persons = generator.generate(5);

Simply two lines :)

For Android

This project has been divided into two parts jrandomizer and arandomizer . arandomizer simply contains wrapper class around Generator class that contains AsyncTask for async data generation for android.

DroidGenerator<Person> generator = new DroidGenerator<>(Person.class);
 List<Person> persons = generator.generate(5);

simply :)

Include in build.gradle

repositories {

maven {

 url 'https://dl.bintray.com/android-infoedge/maven/'

}

  
}

For module

//For android to take advantage of AsyncTask compile 'com.infoedge:arandomizer:0.1-beta1'

or

//Pure java only compile 'com.infoedge:jrandomizer:0.1-beta1'

Inspirations

https://www.mockaroo.com/

https://github.com/ragunathjawahar/android-saripaar

##License

Copyright 2016 Info Edge India Limited

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

The open picker is the fastest way to get files from OneDrive and OneDrive for Business into your Android app. OneDrive-Picker-Android provides a set of Java APIs that your app can use to browse, select, and download files stored in your user's OneDrive.

You can also get shareable links to files - great for sending to friends, coworkers, and relatives. The open picker also lets your app get thumbnails of image and video files so you don't have to build them yourself.

This is a sample app that is part of a blog post about how to architect android application using the Uncle Bob's clean architecture approach.

The in app purchase system provided by Google is missing one very important thing. This tool will allow app developers to provide their users with codes to be redeemed in app for extra content.

This system uses Parse.com as a simple and free backend to manage your users and codes. All you need to do is create a free account and setup your app. Once you have your client and application keys, you are ready to go.

A SwipeMenu for ListView.

This Java library provides an implementation of macaroons, which are flexible authorization tokens that work great in distributed systems.

Like cookies, macaroons are bearer tokens that enable applications to ascertain whether their holders' actions are authorized. But macaroons are better than cookies!

This project shows how to make simple Burger buttons (animated menu buttons).

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