Skip to content

Instantly share code, notes, and snippets.

🏊
meditating

curryisdrink BumpeiShimada

🏊
meditating
Block or report user

Report or block BumpeiShimada

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@BumpeiShimada
BumpeiShimada / gist:df59386b6f62c54d105a28d71bb24d0a
Created Jul 9, 2019
A function enables text data line breaking
View gist:df59386b6f62c54d105a28d71bb24d0a
const lines = tweet.split("\\n").map(function(line) {
return <p className="line-wrap">{line}</p>;
});
View LoginLogic.java
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!!
View LoginLogicUnitTest.groovy
class LoginLogicUnitTest extends Specification {
private CandidateLoginLogic logic
def setup(){
logic = new CandidateLoginLogic()
// Mocking autowired methods
OriginalTimeManager timeManager = Mock()
logic.metaClass.setAttribute(logic, "timeManager", timeManager)
View LoginLogic.java
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
*/
View DateEmptyValidator.java
@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() {
View ValidatorFactory.java
@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.
View ValidationService.java
@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);
});
View ValidateType.java
/**
* Types for categorizing validation classes
*/
enum ValidateType {
/**
* Applicable to all events
*/
ALL_EVENTS,
View BaseValidator.java
/**
* 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();
View validate.test.js
describe('isEmpty method with the argument', () => {
const validate = require('./validate');
describe.each`
str | expected
${null} | ${true}
${""} | ${true}
${"word"} | ${false}
`('$str', ({str, expected}) => {
test(`returns ${expected}`, () => {
You can’t perform that action at this time.