🏊♂️
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
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func main() { | |
now := time.Now() |
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
const lines = tweet.split("\\n").map(function(line) { | |
return <p className="line-wrap">{line}</p>; | |
}); |
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
public class LoginLogic { | |
// ... | |
/** | |
* @return whether current date is after or equal to graduate year's 1st April | |
* NOTE FOR READERS: In Japan, students commonly graduates at the end of March | |
*/ | |
boolean isAfterServiceGraduateDate() { | |
// Let's create a test before implementation!! |
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
class LoginLogicUnitTest extends Specification { | |
private CandidateLoginLogic logic | |
def setup(){ | |
logic = new CandidateLoginLogic() | |
// Mocking autowired methods | |
OriginalTimeManager timeManager = Mock() | |
logic.metaClass.setAttribute(logic, "timeManager", timeManager) |
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
public class LoginLogic { | |
@Autowired | |
private OriginalTimeManager timeManager; // This is an in-house class for managing data related to dates | |
/** | |
* @param graduateYear | |
* @return whether current date is after or equal to graduate year's 1st April | |
* @throws NullPointerException if the param graduateYear is null | |
*/ |
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
@Component | |
public class DateEmptyValidator implements BaseValidator { | |
@Override | |
public void validate(EventForm form, List<String> errors) { | |
validateStartDate(form, errors); | |
validateEndDate(form, errors); | |
} | |
@Override | |
public ValidateType getValidateType() { |
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
@Component | |
@AllArgsConstructor(onConstructor = @__(@Autowired)) | |
public class ValidatorFactory { | |
// All concrete classes of an interface can be asserted like this in Spring. | |
// If you want to know more, see: https://dzone.com/articles/load-all-implementors | |
private List<BaseValidator> validators; | |
/** | |
* Filter out all unnecessary validation classes by checking event types | |
* and returns only needed ones. |
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
@Service | |
@AllArgsConstructor(onConstructor = @__(@Autowired)) | |
public class ValidationService { | |
private ValidatorFactory factory; | |
public void execute(boolean isExclusive, EventForm form, List<String> errors) { | |
List<BaseValidator> validators = factory.get(isExclusive); | |
validators.forEach(validator -> { | |
validator.validate(form, errors); | |
}); |
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
/** | |
* Types for categorizing validation classes | |
*/ | |
enum ValidateType { | |
/** | |
* Applicable to all events | |
*/ | |
ALL_EVENTS, |
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
/** | |
* The base class for validating EventForm data | |
*/ | |
public interface BaseValidator { | |
// Argument "errors" should be replaced with error handling class. | |
// In actual case, when "errors" are not empty a program detect it and understand that there are errors. | |
void validate(EventForm form, List<String> errors); | |
ValidateType getValidateType(); |
NewerOlder