1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.room.integration.testapp.test; 18 19 import androidx.room.integration.testapp.vo.Address; 20 import androidx.room.integration.testapp.vo.Coordinates; 21 import androidx.room.integration.testapp.vo.Pet; 22 import androidx.room.integration.testapp.vo.School; 23 import androidx.room.integration.testapp.vo.Toy; 24 import androidx.room.integration.testapp.vo.User; 25 26 import java.util.ArrayList; 27 import java.util.Date; 28 import java.util.List; 29 import java.util.UUID; 30 31 public class TestUtil { createUsersArray(int... ids)32 public static User[] createUsersArray(int... ids) { 33 User[] result = new User[ids.length]; 34 for (int i = 0; i < ids.length; i++) { 35 result[i] = createUser(ids[i]); 36 } 37 return result; 38 } 39 createUsersList(int... ids)40 public static List<User> createUsersList(int... ids) { 41 List<User> result = new ArrayList<>(); 42 for (int id : ids) { 43 result.add(createUser(id)); 44 } 45 return result; 46 } 47 createUser(int id)48 public static User createUser(int id) { 49 User user = new User(); 50 user.setId(id); 51 user.setName(UUID.randomUUID().toString()); 52 user.setLastName(UUID.randomUUID().toString()); 53 user.setAge((int) (10 + Math.random() * 50)); 54 user.setCustomField(UUID.randomUUID().toString()); 55 user.setBirthday(new Date()); 56 return user; 57 } 58 createPet(int id)59 public static Pet createPet(int id) { 60 Pet pet = new Pet(); 61 pet.setPetId(id); 62 pet.setName(UUID.randomUUID().toString()); 63 pet.setAdoptionDate(new Date()); 64 return pet; 65 } 66 createToyForPet(Pet pet, int toyId)67 public static Toy createToyForPet(Pet pet, int toyId) { 68 Toy toy = new Toy(); 69 toy.setName("toy " + toyId); 70 toy.setId(toyId); 71 toy.setPetId(pet.getPetId()); 72 return toy; 73 } 74 createPetsForUser(int uid, int petStartId, int count)75 public static Pet[] createPetsForUser(int uid, int petStartId, int count) { 76 Pet[] pets = new Pet[count]; 77 for (int i = 0; i < count; i++) { 78 Pet pet = createPet(petStartId++); 79 pet.setUserId(uid); 80 pets[i] = pet; 81 } 82 return pets; 83 } 84 createSchool(int id, int managerId)85 public static School createSchool(int id, int managerId) { 86 School school = new School(); 87 school.setId(id); 88 school.setName(UUID.randomUUID().toString()); 89 school.setManager(createUser(managerId)); 90 school.setAddress(createAddress()); 91 return school; 92 } 93 createAddress()94 private static Address createAddress() { 95 Address address = new Address(); 96 address.setCoordinates(createCoordinates()); 97 address.setPostCode((int) (Math.random() * 1000 + 1000)); 98 address.setState(UUID.randomUUID().toString().substring(0, 2)); 99 address.setStreet(UUID.randomUUID().toString()); 100 return address; 101 } 102 createCoordinates()103 private static Coordinates createCoordinates() { 104 Coordinates coordinates = new Coordinates(); 105 coordinates.lat = Math.random(); 106 coordinates.lng = Math.random(); 107 return coordinates; 108 } 109 TestUtil()110 private TestUtil() { 111 } 112 } 113