BAEL-4071 - Get advised method info in Spring AOP
Fixing identation
This commit is contained in:
parent
73af581e18
commit
0c926e7441
@ -23,9 +23,6 @@ public class Account {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Account{" +
|
||||
"accountNumber='" + accountNumber + '\'' +
|
||||
", balance=" + balance +
|
||||
'}';
|
||||
return "Account{" + "accountNumber='" + accountNumber + '\'' + ", balance=" + balance + '}';
|
||||
}
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ import java.util.Arrays;
|
||||
@Component
|
||||
public class BankAccountAspect {
|
||||
|
||||
@Before(value="@annotation(com.baeldung.method.info.AccountOperation)")
|
||||
@Before(value = "@annotation(com.baeldung.method.info.AccountOperation)")
|
||||
public void getAccountOperationInfo(JoinPoint joinPoint) {
|
||||
|
||||
//Method Information
|
||||
// Method Information
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
|
||||
System.out.println("full method description: " + signature.getMethod());
|
||||
@ -26,23 +26,26 @@ public class BankAccountAspect {
|
||||
|
||||
System.out.println("declaring type: " + signature.getDeclaringType());
|
||||
|
||||
//Method args
|
||||
// Method args
|
||||
System.out.println("Method args names:");
|
||||
Arrays.stream(signature.getParameterNames()).forEach(s -> System.out.println("arg name: " + s));
|
||||
Arrays.stream(signature.getParameterNames())
|
||||
.forEach(s -> System.out.println("arg name: " + s));
|
||||
|
||||
System.out.println("Method args types:");
|
||||
Arrays.stream(signature.getParameterTypes()).forEach(s -> System.out.println("arg type: " + s));
|
||||
Arrays.stream(signature.getParameterTypes())
|
||||
.forEach(s -> System.out.println("arg type: " + s));
|
||||
|
||||
System.out.println("Method args values:");
|
||||
Arrays.stream(joinPoint.getArgs()).forEach(o -> System.out.println("arg value: " + o.toString()));
|
||||
Arrays.stream(joinPoint.getArgs())
|
||||
.forEach(o -> System.out.println("arg value: " + o.toString()));
|
||||
|
||||
//Additional Information
|
||||
// Additional Information
|
||||
System.out.println("returning type: " + signature.getReturnType());
|
||||
System.out.println("method modifier: " + Modifier.toString(signature.getModifiers()));
|
||||
Arrays.stream(signature.getExceptionTypes())
|
||||
.forEach(aClass -> System.out.println("exception type: " + aClass));
|
||||
|
||||
//Method annotation
|
||||
// Method annotation
|
||||
Method method = signature.getMethod();
|
||||
AccountOperation accountOperation = method.getAnnotation(AccountOperation.class);
|
||||
System.out.println("Account operation annotation: " + accountOperation);
|
||||
@ -50,4 +53,3 @@ public class BankAccountAspect {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class BankAccountService {
|
||||
@AccountOperation(operation = "withdraw")
|
||||
public void withdraw(Account account, Double amount) throws WithdrawLimitException {
|
||||
|
||||
if(amount > 500.0) {
|
||||
if (amount > 500.0) {
|
||||
throw new WithdrawLimitException("Withdraw limit exceeded.");
|
||||
}
|
||||
|
||||
@ -26,5 +26,4 @@ public class BankAccountService {
|
||||
return RandomUtils.nextDouble();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ class BankAccountServiceIntegrationTest {
|
||||
|
||||
@Test
|
||||
void withdrawWhenLimitReached() {
|
||||
Assertions.assertThatExceptionOfType(WithdrawLimitException.class).isThrownBy(() -> bankAccountService.withdraw(account, 600.0));
|
||||
Assertions.assertThatExceptionOfType(WithdrawLimitException.class)
|
||||
.isThrownBy(() -> bankAccountService.withdraw(account, 600.0));
|
||||
assertTrue(account.getBalance() == 2000.0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user