-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
3 changed files
with
161 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package byx.aop.test; | ||
|
||
import byx.aop.exception.NotImplementedException; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import static byx.aop.AOP.*; | ||
import static byx.aop.core.MethodInterceptor.*; | ||
|
||
public class ExtendTest | ||
{ | ||
public static abstract class User | ||
{ | ||
public abstract void setUsername(String username); | ||
public abstract String getUsername(); | ||
public abstract void setPassword(String password); | ||
public abstract String getPassword(); | ||
} | ||
|
||
public static class Student | ||
{ | ||
public int getId() | ||
{ | ||
return 1001; | ||
} | ||
|
||
public String getName() | ||
{ | ||
return "XiaoMing"; | ||
} | ||
} | ||
|
||
@Test | ||
public void test1() | ||
{ | ||
User user = extend(User.class, delegateTo(new Object() | ||
{ | ||
private String username; | ||
|
||
public void setUsername(String username) | ||
{ | ||
this.username = username; | ||
} | ||
|
||
public String getUsername() | ||
{ | ||
return username; | ||
} | ||
})); | ||
|
||
user.setUsername("XiaoMing"); | ||
assertEquals("XiaoMing", user.getUsername()); | ||
assertThrows(NotImplementedException.class, () -> user.setPassword("123456")); | ||
assertThrows(NotImplementedException.class, user::getPassword); | ||
} | ||
|
||
@Test | ||
public void test2() | ||
{ | ||
Student student = extend(Student.class, delegateTo(new Object() | ||
{ | ||
public int getId() | ||
{ | ||
return 2002; | ||
} | ||
})); | ||
|
||
assertEquals(2002, student.getId()); | ||
assertThrows(NotImplementedException.class, student::getName); | ||
} | ||
} |