Random data for test : Unit Test « Development Class « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Development Class » Unit TestScreenshots 
Random data for test
 

/*
 * Copyright 2005 Joe Walker
 *
 * 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.
 */


import java.util.Random;

/**
 @author Joe Walker [joe at getahead dot ltd dot uk]
 */
public class RandomData
{
    /**
     @param isUS US numbers look different to UK ones
     @return A phone number
     */
    public static String getPhoneNumber(boolean isUS)
    {
        String phoneNumber;
        if (isUS)
        {
            // US
            phoneNumber = "+1 (" + random.nextInt(9+ random.nextInt(9+ random.nextInt(9") "
                + random.nextInt(9+ random.nextInt(9+ random.nextInt(9" - "
                + random.nextInt(9+ random.nextInt(9+ random.nextInt(9+ random.nextInt(9);
        }
        else
        {
            // UK
            phoneNumber = "+44 (0) 1" + random.nextInt(9+ random.nextInt(9+ random.nextInt(9)
                " " + random.nextInt(9+ random.nextInt(9+ random.nextInt(9+ random.nextInt(9)
                + random.nextInt(9+ random.nextInt(9);
        }
        return phoneNumber;
    }

    public static String getFirstName()
    {
        return FIRSTNAMES[random.nextInt(FIRSTNAMES.length)];
    }

    public static String getSurname()
    {
        return SURNAMES[random.nextInt(SURNAMES.length)];
    }

    public static String getFullName()
    {
        return getFirstName() " " + getSurname();
    }

    public static String getAddress()
    {
        String housenum = (random.nextInt(991" ";
        String road1 = ROADS1[random.nextInt(ROADS1.length)];
        String road2 = ROADS2[random.nextInt(ROADS2.length)];
        int townNum = random.nextInt(TOWNS.length);
        String town = TOWNS[townNum];
        return housenum + road1 + " " + road2 + ", " + town;
    }

    public static String[] getAddressAndNumber()
    {
        String[] reply = new String[2];

        String housenum = (random.nextInt(991" ";
        String road1 = ROADS1[random.nextInt(ROADS1.length)];
        String road2 = ROADS2[random.nextInt(ROADS2.length)];
        int townNum = random.nextInt(TOWNS.length);
        String town = TOWNS[townNum];

        reply[0= housenum + road1 + " " + road2 + ", " + town;
        reply[1= getPhoneNumber(townNum < 5);

        return reply;
    }

    public static float getSalary()
    {
        return Math.round(10 90 * random.nextFloat()) 1000;
    }

    private static final Random random = new Random();

    private static final String[] FIRSTNAMES =
    {
        "Fred""Jim""Shiela""Jack""Betty""Jacob""Martha""Kelly",
        "Luke""Matt""Gemma""Joe""Ben""Jessie""Leanne""Becky",
        "William""Jo"
    };

    private static final String[] SURNAMES =
    {
        "Sutcliffe""MacDonald""Duckworth""Smith""Wisner"
        "Nield""Turton""Trelfer""Wilson""Johnson""Daniels",
        "Jones""Wilkinson""Wilton"
    };

    private static final String[] ROADS1 =
    {
        "Green""Red""Yellow""Brown""Blue""Black""White",
    };

    private static final String[] ROADS2 =
    {
        "Close""Drive""Street""Avenue""Crescent""Road""Place",
    };

    private static final String[] TOWNS =
    {
        "San Mateo""San Francisco""San Diego""New York""Atlanta",
        "Sandford""York""London""Coventry""Exeter""Knowle",
    };
}

   
  
Related examples in the same category
1. Set JUnit Test case fail information
2. JUnit assertEquals: Float With Delta
3. Assert equals: int
4. Assert equals: Long
5. JUnit assertEquals With Message
6. JUnit assertTrue
7. JUnit assertTrue: ObjectArray
8. Before annotation
9. JUnit BeforeClass
10. JUnit Extends TestCase
11. JUnit Ignore
12. Simple test with JUnit
13. JUnit Test Case With Expected Exception
14. JUnit Test Setup
15. Simple use of JUnit to test ArrayListSimple use of JUnit to test ArrayList
16. Debug frameDebug frame
17. Error HandlerError Handler
18. Redirect or reassign some standard descriptors
19. Utilities for debugging
20. Testing class ClassTesting class Class
21. Simple utility for testing program outputSimple utility for testing program output
22. Assertion tool for debugging
23. Simple DebuggingSimple Debugging
24. Demonstration of Design by Contract (DBC) combined with white-box unit testingDemonstration of Design by Contract (DBC) combined with white-box unit testing
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.