I have a class Book
:
package book;
public class Book {
private String title;
public Book(String title) {
this.title = title;
}
public boolean equals(Object object) {
if(object instanceof Book) {
Book book = (Book) object;
return this.title.equals(book.title);
}
return false;
}
}
This is my Aspect class and Configuration class:
package book;
@Aspect
@Component
public class Logging {
@Pointcut("execution(* java.lang.Object.equals(..))")
private void equals() {}
@Before("equals()")
public void log() {
System.out.println("logging...");
}
}
package book;
@Configuration
@ComponentScan
@EnableAspectJAutoProxy
public class Config {
}
And this is my test class:
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = Config.class)
public class LoggingTest {
@Value("#{new book.Book('book1')}")
private Book book;
@Value("#{new book.Book('book2')}")
private Book book2;
@Test
public void test() {
assertFalse(book.equals(book2));
}
}
This test class run successfully. but the expected logging...
was not printed. Could you please tell me what's wrong in my code?
Thanks in advance!