Untitled

mail@pastecode.io avatar
unknown
java
6 months ago
2.9 kB
0
Indexable
Never
This task will check your Spring AOP knowledge. This application is written with
Spring Boot version 2.2.2.RELEASE and Java 8. You are writing an aspect that will do
some logging whenever some method of the StringManipulationService class is
called.
Here is the StringManipulationService class that will be used for testing:
StringManipulationService.java
package com.codility.external;
import org.springframework.stereotype.Service:
@Service
public class StringManipulationService (
publio String reverseString(String target) (
return new StringBuilder (target). reverse(). toString():
public String copitalizeAl1Letters(String target) (
1f (target as null) (
throw new IllegalStateException("String must not be null*);
return target, toUpperCase():
public String removeAl1hitespaces (String target) ‹
return target. replace 11(*|\s+*
**)
public String removeAllNumbers (String target) 1
1f (target a null) (
throw new IllegalStateException("String must not be null*);

Important
The class that you are implementing should be named "StringManipulationAspect*
and the package should be com.codility external in order for the tests to work. Pleast
do not modify these names.
Tasks
Your tasks are to:
1. Write an aspect method that will log "Method execution started* with info log
level before any method from the StringManipulationService class is called.
2. Write an aspect method that will log "Finished successfully" with info log level
whenever the capitalizeAlILetters0 method from the StringManipulationService
class has returned successfully.
3. Write an aspect method that will log execution duration of the
removeAllWhitespaces method with info log level whenever the
removeAllWhitespaces0 method from the StringManipulationService class is
called. The message should be in the format: "Duration in milliseconds: 5', whel
the number 5 is variable and represents the duration time needed to execute thi
function.
4. Write an aspect method that will log Removed all numbers* with info loa level
whenever the removeAllNumbers method from the String ManipulationService
class has returned.
5. Write an aspect method that will log error messages from the exception that wi
thrown with error log level whenever the removeAllNumbers0 method from the
StringManipulationService throws an IllegalStateException.
Requirements
1. Make sure that you use the logger already provided in your initial code.
2. Make sure that the logged sentences match the exact ones in the description,
otherwise the tests will fail.

Requirements
1. Make sure that you use the logger already provided in your initial code.
2. Make sure that the logged sentences match the exact ones in the description,
otherwise the tests will fail.
Logging examples
Here are examples of how to use the provided logger.
log. info("Method execution started*)
log.error ("Error state*);