### Question:
DefaultInternalAccountTagService { public void validate(List<AccountTag> accountTags) { for (AccountTagResponse defaultTag : getDefaults().getResponses()) { Optional<AccountTag> requestContainsUnmodifiableTag = accountTags .stream() .filter(e -> e.getTagKey().equals(defaultTag.getKey())) .findFirst(); if (requestContainsUnmodifiableTag.isPresent()) { throw new BadRequestException(String.format("Tag with %s key exist as an unmodifiable tag.", defaultTag.getKey())); } } for (AccountTag accountTag : accountTags) { Pattern pattern = Pattern.compile(ACCOUNT_TAG_PATTERN); Matcher keyMatcher = pattern.matcher(accountTag.getTagKey()); Matcher valueMatcher = pattern.matcher(accountTag.getTagValue()); if (!keyMatcher.matches()) { throw new BadRequestException( String.format("The key '%s' can only can not start with microsoft or azure or aws or windows or space", accountTag.getTagKey())); } if (!valueMatcher.matches()) { throw new BadRequestException( String.format("The value '%s' can only can not start with microsoft or azure or aws or windows or space", accountTag.getTagValue())); } if (isAccountTagContainsTemplate(accountTag.getTagKey()) && isAccountTagInvalid(accountTag.getTagKey())) { throw new BadRequestException( String.format("The key '%s' of the tag contains invalid templates", accountTag.getTagKey())); } if (isAccountTagContainsTemplate(accountTag.getTagValue()) && isAccountTagInvalid(accountTag.getTagValue())) { throw new BadRequestException( String.format("The value '%s' of the tag contains invalid templates", accountTag.getTagValue())); } } } DefaultInternalAccountTagService(CloudbreakResourceReaderService cloudbreakResourceReaderService); @PostConstruct void init(); void merge(List<AccountTagResponse> accountTagResponses); void validate(List<AccountTag> accountTags);  }### Answer:
@Test public void testValidateWhenKeyAndValueIsFineShouldDoNothing() { underTest.validate(accountTags("apple", "apple")); }
@Test public void testValidateWhenKeyContainsMicrosoftShouldThrowBadRequest() { assertThrows(BadRequestException.class, () -> underTest.validate(accountTags("microsoftapple", "apple"))); }
@Test public void testValidateWhenKeyContainsAwsShouldThrowBadRequest() { assertThrows(BadRequestException.class, () -> underTest.validate(accountTags("awsapple", "apple"))); }
@Test public void testValidateWhenKeyContainsAwsButNotStartingWithShouldBeFine() { underTest.validate(accountTags("appleaws", "apple")); }
@Test public void testValidateWhenValueContainsMicrosoftShouldThrowBadRequest() { assertThrows(BadRequestException.class, () -> underTest.validate(accountTags("apple", "microsoftapple"))); }
@Test public void testValidateWhenValueContainsAwsShouldThrowBadRequest() { assertThrows(BadRequestException.class, () -> underTest.validate(accountTags("apple", "awsapple"))); }
@Test public void testInValidateWhenValueContainsTooMuchMustache() { assertThrows(BadRequestException.class, () -> underTest.validate(accountTags("apple", "{{{{pear}}}"))); }
@Test public void testInValidateWhenKeyContainsTooMuchMustache() { assertThrows(BadRequestException.class, () -> underTest.validate(accountTags("{{{{apple}}}", "pear"))); }
@Test public void testInValidateWhenValueContainsInvalidModelKey() { assertThrows(BadRequestException.class, () -> underTest.validate(accountTags("pear", "{{{creatorcrn}}}"))); }
@Test public void testInValidateWhenKeyContainsInvalidModelKey() { assertThrows(BadRequestException.class, () -> underTest.validate(accountTags("{{{creatorcrn}}}", "pear"))); }
@Test public void testValidateWhenValueContainsvalidModelKey() { underTest.validate(accountTags("pear", "{{{creatorCrn}}}")); }
@Test public void testValidateWhenKeyContainsvalidModelKey() { underTest.validate(accountTags("{{{creatorCrn}}}", "pear")); }