forked from Devskiller/jfairy
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Devskiller#67 from andidev/refactor-credit-card-pr…
…ovider Refactor credit card producer into a credit card provider
- Loading branch information
Showing
4 changed files
with
49 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 5 additions & 22 deletions
27
src/main/java/io/codearte/jfairy/producer/payment/CreditCard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/io/codearte/jfairy/producer/payment/CreditCardProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.codearte.jfairy.producer.payment; | ||
|
||
import com.google.inject.Provider; | ||
import io.codearte.jfairy.data.DataMaster; | ||
import io.codearte.jfairy.producer.DateProducer; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.Period; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class CreditCardProvider implements Provider<CreditCard> { | ||
|
||
private static final Period DEFAULT_VALIDITY = Period.months(36); | ||
private static final String DATA_KEY = "cardVendors"; | ||
|
||
private final DataMaster dataMaster; | ||
private final DateProducer dateProducer; | ||
|
||
@Inject | ||
public CreditCardProvider(DataMaster dataMaster, DateProducer dateProducer) { | ||
this.dataMaster = dataMaster; | ||
this.dateProducer = dateProducer; | ||
} | ||
|
||
@Override | ||
public CreditCard get() { | ||
String cardVendor = dataMaster.getRandomValue(DATA_KEY); | ||
DateTime expiryDate = dateProducer.randomDateBetweenNowAndFuturePeriod(DEFAULT_VALIDITY); | ||
return new CreditCard(cardVendor, expiryDate); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters