-
-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Besok
committed
Oct 24, 2019
1 parent
20b4195
commit 630532c
Showing
14 changed files
with
321 additions
and
54 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
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
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
15 changes: 15 additions & 0 deletions
15
role-object/src/main/java/com/iluwatar/roleobject/BorrowerRole.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 |
---|---|---|
@@ -1,4 +1,19 @@ | ||
package com.iluwatar.roleobject; | ||
|
||
public class BorrowerRole extends CustomerRole{ | ||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String borrow(){ | ||
return String.join(" ", | ||
"A borrower",name,"wants to get some money."); | ||
} | ||
|
||
} |
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
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: 4 additions & 23 deletions
27
role-object/src/main/java/com/iluwatar/roleobject/CustomerRole.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 |
---|---|---|
@@ -1,25 +1,6 @@ | ||
package com.iluwatar.roleobject; | ||
|
||
import java.util.Optional; | ||
|
||
public class CustomerRole extends Customer{ | ||
@Override | ||
public boolean addRole(Role role) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean hasRole(Role role) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean remRole(Role role) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public <T extends Customer> Optional<T> getRole(Role role, Class<T> expectedRole) { | ||
return Optional.empty(); | ||
} | ||
} | ||
/** | ||
* Key abstraction for segregated roles | ||
*/ | ||
public abstract class CustomerRole extends CustomerCore{} |
25 changes: 24 additions & 1 deletion
25
role-object/src/main/java/com/iluwatar/roleobject/InvestorRole.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 |
---|---|---|
@@ -1,4 +1,27 @@ | ||
package com.iluwatar.roleobject; | ||
|
||
public class InvestorRole extends CustomerRole{ | ||
public class InvestorRole extends CustomerRole { | ||
private String name; | ||
private long amountToInvest; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public long getAmountToInvest() { | ||
return amountToInvest; | ||
} | ||
|
||
public void setAmountToInvest(long amountToInvest) { | ||
this.amountToInvest = amountToInvest; | ||
} | ||
|
||
public String invest() { | ||
return String.join(" ", | ||
"Investor", name, "has invested", String.valueOf(amountToInvest), "dollars"); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
role-object/src/test/java/com/iluwatar/roleobject/ApplicationRoleObjectTest.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,13 @@ | ||
package com.iluwatar.roleobject; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ApplicationRoleObjectTest { | ||
|
||
@Test | ||
public void mainTest() { | ||
ApplicationRoleObject.main(new String[]{}); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
role-object/src/test/java/com/iluwatar/roleobject/BorrowerRoleTest.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,18 @@ | ||
package com.iluwatar.roleobject; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class BorrowerRoleTest { | ||
|
||
@Test | ||
public void borrowTest() { | ||
BorrowerRole borrowerRole = new BorrowerRole(); | ||
borrowerRole.setName("test"); | ||
String res = "A borrower test wants to get some money."; | ||
|
||
Assert.assertEquals(borrowerRole.borrow(),res); | ||
} | ||
} |
Oops, something went wrong.