@BeforeClass
public static void createCompanies(){
System.out.println("Setting companies data! ");
instances.put("company1",adminServiceTesting.createCompany("ORG","Free@88",34553453,"ORG@.com",callForCompany()));
instances.put("company2",adminServiceTesting.createCompany("PPP","Trading@000",4536579,"PPP@.com",callForCompany()));
}
instances = new HashMap<String,CompanyObject>();
//String - ключ, тип строка, функция hashCode() встроенная, можно не переопределять
//CompanyObject - ваш объект с данными, на hashCode() пофиг ибо он использоваться не будет совсем
instance.put("comp1", objectComp1); //будет добавлен
instance.put("comp2", objectComp1); //будет добавлен т.к. хэш ключа будет другим
instance.put("comp1", objectComp6); //оп, коллизия, в позиции "comp1" будет заменено "Значение"(objectComp1) на (objectComp6)
for (Object key : instance.keySet())
if (что то)
instance.remove(key);
for(Iterator<Map.Entry<String, CompanyObject>> it = instance.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, CompanyObject> entry = it.next();
if(что то) {
it.remove();
}
}
for (Object obj : new ArrayList<Object>(instance.keySet()))
if (что то)
instance.remove(key);
public class CouponSystemUsersDataSetter {
private static CouponSystemBeanFactory couponBeanFactory = CouponSystemBeanFactory.getCouponSystemBeanFactoryInstance();
private static CompanyServiceTesting companyServiceTesting = CompanyServiceTesting.companyServiceTestingInstance();
private static AdminServiceTesting adminServiceTesting = AdminServiceTesting.getAdminServiceTestingInstance();
public static Map<String,Object> getInstances() {
return instances;
}
private static Map<String,Object> instances = new HashMap<>();
private RegistrationData callForRegistration(){
return couponBeanFactory.getBeanInstance("registration" , RegistrationData.class);
}
private static Company callForCompany(){
return couponBeanFactory.getBeanInstance("company" , Company.class);
}
private static Coupon callForCoupon(){
return couponBeanFactory.getBeanInstance("coupon" , Coupon.class);
}
private Customer callForCustomer(){
return couponBeanFactory.getBeanInstance("customer",Customer.class);
}
private Employee callForEmployee(){
return couponBeanFactory.getBeanInstance("employee",Employee.class);
}
private User callForUser(){
return couponBeanFactory.getBeanInstance("user",User.class);
}
@Before
public void createCoupons(){
System.out.println("Setting coupons data! ");
Map<String,Object> instances = getInstances();
instances.put("coupon1",companyServiceTesting.createCompanyCoupon((Company)instances.get("company1"),callForCoupon(),"Travelling low prices","FamilyTravelling",
23,765475475,"C://ProgramFiles",35.8, CouponType.TRAVELING, CouponSystemDate.dateFormat(2017,12,12)
,CouponSystemDate.dateFormat(2019,12,12)));
instances.put("coupon2",companyServiceTesting.createCompanyCoupon((Company)instances.get("company2"),callForCoupon(),"Camping low prices","FamilyCamping",
13,9999887,"C://ProgramFiles",55.8, CouponType.CAMPING, CouponSystemDate.dateFormat(2016,10,10)
,CouponSystemDate.dateFormat(2018,9,1)));
instances.put("coupon3",companyServiceTesting.createCompanyCoupon((Company)instances.get("company1"),callForCoupon(),"Electricity low prices","Electricity",
12,5424352,"C://ProgramFiles",25.8, CouponType.ELECTRICITY, CouponSystemDate.dateFormat(2017,7,3)
,CouponSystemDate.dateFormat(2018,4,5)));
instances.put("coupon4",companyServiceTesting.createCompanyCoupon((Company)instances.get("company2"),callForCoupon(),"Food low prices","FamilyDinner",
53,989873,"C://ProgramFiles",15.8, CouponType.FOOD, CouponSystemDate.dateFormat(2017,4,11)
,CouponSystemDate.dateFormat(2018,4,11)));
instances.put("coupon5",companyServiceTesting.createCompanyCoupon((Company)instances.get("company1"),callForCoupon(),"Health insurance low prices","FamilyInsurance",
83,33344455,"C://ProgramFiles",88.8, CouponType.HEALTH, CouponSystemDate.dateFormat(2017,8,9)
,CouponSystemDate.dateFormat(2018,8,9)));
instances.put("coupon6",companyServiceTesting.createCompanyCoupon((Company)instances.get("company2"),callForCoupon(),"Sport village low prices","SportVacation",
73,6665432,"C://ProgramFiles",95.8, CouponType.SPORTS, CouponSystemDate.dateFormat(2017,7,11)
,CouponSystemDate.dateFormat(2019,7,11)));
}
@BeforeClass
public static void createCompanies(){
System.out.println("Setting companies data! ");
Map<String,Object> instances = getInstances();
instances.put("company1",adminServiceTesting.createCompany("ORG","Free@88",34553453,"ORG@.com",callForCompany()));
instances.put("company2",adminServiceTesting.createCompany("PPP","Trading@000",4536579,"PPP@.com",callForCompany()));
}
@Test
public void createCustomers(){
System.out.println("Setting customer data! ");
Map<String,Object> instances = getInstances();
instances.put("customer1",companyServiceTesting.createCustomer(787654,"Natali@gmail.com","Nata000@99","Nata","Vladimi",callForCustomer()));
instances.put("customer2",companyServiceTesting.createCustomer(980982,"Maks@gmail.com","MMM@mmm999","Maks","Burkov",callForCustomer()));
instances.put("customer3",companyServiceTesting.createCustomer(888776655,"Sasha@gamil.com","SSS0001988@","Sasha","Sashkoviz",callForCustomer()));
instances.put("customer4",companyServiceTesting.createCustomer(4443332,"Lumila@gmail.com","lumi00088@","Lumila","Lumovich",callForCustomer()));
instances.put("customer5",companyServiceTesting.createCustomer(222888444,"Yani@gmail.com","yani@_777","Yani","Yovi",callForCustomer()));
instances.put("customer6",companyServiceTesting.createCustomer(4325432,"Yoni@gmail.com","Yoni@09087","Yoni","Yonivich",callForCustomer()));
}
@Before
public void createEmployees(){
System.out.println("Setting employee data! ");
Map<String,Object> instances = getInstances();
instances.put("employee1",companyServiceTesting.createCompanyEmployee(callForEmployee(),(Company)instances.get("company1"),222222,"Rahel@gmail.com","Israel","Rahel","Rehelovich","059876534"));
instances.put("employee2",companyServiceTesting.createCompanyEmployee(callForEmployee(),(Company)instances.get("company2"),111111,"Yosi@gmail.com","Israel","Yosi","Izhak","055312567"));
instances.put("employee3",companyServiceTesting.createCompanyEmployee(callForEmployee(),(Company)instances.get("company1"),45353,"Pavel@gmail.com","Israel","Pavel","Pavlov","050689321"));
instances.put("employee4",companyServiceTesting.createCompanyEmployee(callForEmployee(),(Company)instances.get("company2"),3498766,"Luba@gmail.com","Israel","Luba","Lubovkina","0547890122"));
instances.put("employee5",companyServiceTesting.createCompanyEmployee(callForEmployee(),(Company)instances.get("company1"),8888453,"Miha@gmail.com","Israel","Miha","Mihuelkin","050934122"));
instances.put("employee6",companyServiceTesting.createCompanyEmployee(callForEmployee(),(Company)instances.get("company2"),9879874,"Avi@gmail.com","Israel","Avi","AviAla","0547334567"));
}
@After
public void createUsers(){
System.out.println("Setting users data! ");
Map<String,Object> instances = getInstances();
Customer c1 = (Customer) instances.get("customer1"); Customer c2 = (Customer) instances.get("customer2"); Customer c3 = (Customer) instances.get("customer3");
Customer c4 = (Customer) instances.get("customer4"); Customer c5 = (Customer) instances.get("customer5"); Customer c6 = (Customer) instances.get("customer6");
instances.put("user1",RegisterServiceTesting.createUser("Customer1",c1.getPassword(),c1.getEmail(),"customer",callForUser()));
instances.put("user2",RegisterServiceTesting.createUser("Customer2",c2.getPassword(),c2.getEmail(),"customer",callForUser()));
instances.put("user3",RegisterServiceTesting.createUser("Customer3",c3.getPassword(),c3.getEmail(),"customer",callForUser()));
instances.put("user4",RegisterServiceTesting.createUser("customer4",c4.getPassword(),c4.getEmail(),"customer",callForUser()));
instances.put("user5",RegisterServiceTesting.createUser("customer5",c5.getPassword(),c5.getEmail(),"customer",callForUser()));
instances.put("user6",RegisterServiceTesting.createUser("customer6",c6.getPassword(),c6.getEmail(),"customer",callForUser()));
}
@AfterClass
public static void setLoginData(){
System.out.println("Setting login data! ");
Map<String,Object> instances = getInstances();
instances.put("login1",instances.get("user1"));
instances.put("login2",instances.get("user2"));
instances.put("login3",instances.get("user3"));
}
@AfterClass
public static void checkTheSetedObjects(){
System.out.println("Checking the setted data! ");
Map<String,Object> instances = getInstances();
Iterator<Map.Entry<String,Object>> iterator = instances.entrySet().iterator();
while (iterator.hasNext()){
Object value = iterator.next().getValue();
System.out.println("Iterated value: "+value);
}
}
private static Map<String,Object> instances = null;
public static Map<String,Object> getInstances() {
if(instances==null){
instances = new HashMap<>();
}else
return instances;
}
@Before
public void createCoupons(){
instances.put("coupon1",companyServiceTesting.createCompanyCoupon((Company)instances.get("company1"),callForCoupon(),"Travelling low prices","FamilyTravelling",
23,765475475,"C://ProgramFiles",35.8, CouponType.TRAVELING, CouponSystemDate.dateFormat(2017,12,12)
,CouponSystemDate.dateFormat(2019,12,12)));
...
@Before
public void createCoupons(){
Object obj = companyServiceTesting.createCompanyCoupon((Company)instances.get("company1"),callForCoupon(),"Travelling low prices","FamilyTravelling",
23,765475475,"C://ProgramFiles",35.8, CouponType.TRAVELING, CouponSystemDate.dateFormat(2017,12,12)
,CouponSystemDate.dateFormat(2019,12,12))
instances.put("coupon1",obj);
...
@AfterClass
public static void checkTheSetedObjects(){
System.out.println("Checking the setted data! ");
Map<String,Object> instances = getInstances();
Iterator<Map.Entry<String,Object>> iterator = instances.entrySet().iterator();
while (iterator.hasNext()){
Object value = iterator.next().getValue();
System.out.println("Iterated value: "+value);
}
}
System.out.println("Checking the setted data! ");
Map<String,Object> instances = getInstances();
for(Map.Entry<String,Object> entry :instances.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println("Iterated key: "+key + " "+"Iterated value: "+value);
Setting companies data!
Setting employee data!
Setting coupons data!
Setting customer data!
Setting users data!
Checking the setted data!
Iterated value: Coupon [id=6665432, title=SportVacation, startDate=2017-07-11, endDate=2019-07-11, amount=73, message=Sport village low prices, price=95.8, image=C://ProgramFiles, type=SPORTS]
Iterated key:coupon6
Iterated value: Coupon [id=6665432, title=SportVacation, startDate=2017-07-11, endDate=2019-07-11, amount=73, message=Sport village low prices, price=95.8, image=C://ProgramFiles, type=SPORTS]
Iterated key:company1
Iterated value: Coupon [id=6665432, title=SportVacation, startDate=2017-07-11, endDate=2019-07-11, amount=73, message=Sport village low prices, price=95.8, image=C://ProgramFiles, type=SPORTS]
Iterated key:company2
Iterated value: Customer{id=4325432, custFirstName='Yoni', custLastName='Yonivich', password='Yoni@09087', email='Yoni@gmail.com'}
Iterated key:coupon4
Iterated value: Customer{id=4325432, custFirstName='Yoni', custLastName='Yonivich', password='Yoni@09087', email='Yoni@gmail.com'}
Iterated key:coupon5
Iterated value: Customer{id=4325432, custFirstName='Yoni', custLastName='Yonivich', password='Yoni@09087', email='Yoni@gmail.com'}
Iterated key:customer5
Iterated value: Customer{id=4325432, custFirstName='Yoni', custLastName='Yonivich', password='Yoni@09087', email='Yoni@gmail.com'}
Iterated key:customer3
Iterated value: User{nickName='customer6', email='Yoni@gmail.com', password='Yoni@09087', role='customer'}
Iterated key:user1
Iterated value: User{nickName='customer6', email='Yoni@gmail.com', password='Yoni@09087', role='customer'}
Iterated key:user5
Iterated value: User{nickName='customer6', email='Yoni@gmail.com', password='Yoni@09087', role='customer'}
Iterated key:user3
Iterated value: Employee{id=9879874, firstName='Avi', lastName='AviAla', email='Avi@gmail.com', phoneNumber='0547334567', country='Israel'}
Iterated key:employee6
Iterated value: Employee{id=9879874, firstName='Avi', lastName='AviAla', email='Avi@gmail.com', phoneNumber='0547334567', country='Israel'}
Iterated key:employee3
Iterated value: Employee{id=9879874, firstName='Avi', lastName='AviAla', email='Avi@gmail.com', phoneNumber='0547334567', country='Israel'}
Iterated key:employee5
Setting login data!
Test successfully accomplished ? true
public class User {
private Long id;
private final String email;
public User(String email) {
this(null, email);
}
public User(Long id, String email) {
this.id = id;
this.email = email;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return email.equals(user.email);
}
@Override
public int hashCode() {
return email.hashCode();
}
}