JAMES-2521 CLI should not depend on data-library
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/eabfa17b Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/eabfa17b Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/eabfa17b Branch: refs/heads/master Commit: eabfa17bd333610a8c70389dc3b7df6c3dbec712 Parents: 31a2fbf Author: Benoit Tellier <[email protected]> Authored: Tue Aug 14 10:56:03 2018 +0700 Committer: Benoit Tellier <[email protected]> Committed: Wed Aug 29 10:11:46 2018 +0700 ---------------------------------------------------------------------- server/container/cli/pom.xml | 4 - .../org/apache/james/rrt/lib/MappingsImpl.java | 286 +++++++++++++++++++ .../org/apache/james/rrt/lib/SeparatorUtil.java | 62 ++++ .../apache/james/rrt/lib/SeparatorUtilTest.java | 50 ++++ .../org/apache/james/rrt/lib/MappingsImpl.java | 286 ------------------- .../rrt/lib/RecipientRewriteTableUtil.java | 36 --- .../rrt/lib/RecipientRewriteTableUtilTest.java | 50 ---- 7 files changed, 398 insertions(+), 376 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/eabfa17b/server/container/cli/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/cli/pom.xml b/server/container/cli/pom.xml index 2975478..b5ba568 100644 --- a/server/container/cli/pom.xml +++ b/server/container/cli/pom.xml @@ -39,10 +39,6 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> - <artifactId>james-server-data-library</artifactId> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> <artifactId>james-server-mailbox-adapter</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/eabfa17b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java ---------------------------------------------------------------------- diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java new file mode 100644 index 0000000..7a7e4b0 --- /dev/null +++ b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java @@ -0,0 +1,286 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.james.rrt.lib; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.Iterator; +import java.util.Optional; +import java.util.StringTokenizer; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import org.apache.james.rrt.lib.Mapping.Type; + +import com.github.steveash.guavate.Guavate; +import com.google.common.base.Joiner; +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +public class MappingsImpl implements Mappings, Serializable { + + private static final long serialVersionUID = 1L; + + private static class DefaultMappingOrderingPolicy { + + private static final Comparator<Mapping> MAPPING_COMPARATOR = Comparator + .<Mapping, Integer>comparing(DefaultMappingOrderingPolicy::typeOrder) + .thenComparing(Mapping::asString); + + private static int typeOrder(Mapping mapping) { + return typeOrder(mapping.getType()); + } + + private static int typeOrder(Mapping.Type type) { + switch (type) { + case Domain: + return 1; + case Group: + return 2; + case Forward: + return 3; + case Regex: + return 4; + case Error: + return 4; + case Address: + return 4; + } + throw new IllegalArgumentException("missing enum handling"); + } + + public Comparator<Mapping> comparator() { + return MAPPING_COMPARATOR; + } + } + + + + public static MappingsImpl empty() { + return builder().build(); + } + + public static MappingsImpl fromRawString(String raw) { + return fromCollection(mappingToCollection(raw)); + } + + public static MappingsImpl fromMappings(Mapping... mappings) { + return fromMappings(Arrays.stream(mappings)); + } + + private static ArrayList<String> mappingToCollection(String rawMapping) { + ArrayList<String> map = new ArrayList<>(); + StringTokenizer tokenizer = new StringTokenizer(rawMapping, SeparatorUtil.getSeparator(rawMapping)); + while (tokenizer.hasMoreTokens()) { + final String raw = tokenizer.nextToken().trim(); + map.add(raw); + } + return map; + } + + public static MappingsImpl fromCollection(Collection<String> mappings) { + return fromMappings(mappings.stream() + .map(Mapping::of)); + } + + public static MappingsImpl fromMappings(Stream<Mapping> mappings) { + return mappings + .reduce(builder(), Builder::add, Builder::merge) + .build(); + } + + public static Builder from(Mappings from) { + Builder builder = new Builder(); + builder.addAll(from); + return builder; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + public static Builder merge(Builder builder1, Builder builder2) { + return builder1.addAll(builder2.build()); + } + + private final ImmutableList.Builder<Mapping> mappings; + + private Builder() { + mappings = ImmutableList.builder(); + } + + public Builder add(String mapping) { + return add(Mapping.of(mapping)); + } + + public Builder add(Mapping mapping) { + mappings.add(mapping); + return this; + } + + public Builder addAll(Mappings mappings) { + this.mappings.addAll(mappings); + return this; + } + + public Builder addAll(Iterable<String> mappings) { + mappings.forEach(this::add); + return this; + } + + public MappingsImpl build() { + return new MappingsImpl(mappings.build() + .stream() + .sorted(new DefaultMappingOrderingPolicy().comparator()) + .collect(Guavate.toImmutableList())); + } + + } + + private final ImmutableList<Mapping> mappings; + + private MappingsImpl(Collection<Mapping> mappings) { + this.mappings = ImmutableList.copyOf(mappings); + } + + @Override + public Iterable<String> asStrings() { + return mappings.stream() + .map(Mapping::asString) + .collect(Guavate.toImmutableList()); + } + + @Override + public boolean contains(Mapping mapping) { + return mappings.contains(mapping); + } + + @Override + public int size() { + return mappings.size(); + } + + @Override + public Mappings remove(Mapping mapping) { + if (mappings.contains(mapping)) { + ArrayList<Mapping> updatedMappings = Lists.newArrayList(mappings); + updatedMappings.remove(mapping); + return new MappingsImpl(updatedMappings); + } + return this; + } + + @Override + public boolean isEmpty() { + return mappings.isEmpty(); + } + + @Override + public Iterator<Mapping> iterator() { + return mappings.iterator(); + } + + @Override + public String serialize() { + return Joiner.on(';').join(asStrings()); + } + + private Predicate<Mapping> hasType(final Mapping.Type type) { + return mapping -> mapping.getType().equals(type); + } + + @Override + public boolean contains(Type type) { + Preconditions.checkNotNull(type); + return mappings.stream() + .anyMatch(hasType(type)); + } + + @Override + public Mappings select(Type type) { + Preconditions.checkNotNull(type); + return fromMappings(mappings.stream() + .filter(hasType(type))); + } + + + @Override + public Mappings exclude(Type type) { + Preconditions.checkNotNull(type); + return fromMappings(mappings.stream() + .filter(hasType(type).negate())); + } + + @Override + public Mapping getError() { + Mappings errors = select(Type.Error); + Preconditions.checkState(!errors.isEmpty()); + return Iterables.getFirst(errors, null); + } + + @Override + public Optional<Mappings> toOptional() { + if (isEmpty()) { + return Optional.empty(); + } + return Optional.of(this); + } + + @Override + public Mappings union(Mappings mappings) { + Preconditions.checkState(mappings != null, "mappings is mandatory"); + return from(this).addAll(mappings).build(); + } + + @Override + public Stream<Mapping> asStream() { + return mappings.stream(); + } + + @Override + public int hashCode() { + return Objects.hashCode(mappings); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof MappingsImpl) { + MappingsImpl other = (MappingsImpl) obj; + return Objects.equal(mappings, other.mappings); + } + return false; + } + + @Override + public String toString() { + return "MappingsImpl{" + + "mappings=" + mappings + + '}'; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/eabfa17b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/SeparatorUtil.java ---------------------------------------------------------------------- diff --git a/server/data/data-api/src/main/java/org/apache/james/rrt/lib/SeparatorUtil.java b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/SeparatorUtil.java new file mode 100644 index 0000000..0d12c44 --- /dev/null +++ b/server/data/data-api/src/main/java/org/apache/james/rrt/lib/SeparatorUtil.java @@ -0,0 +1,62 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.rrt.lib; + +import java.util.Optional; + +import org.apache.james.util.OptionalUtils; + +public class SeparatorUtil { + /** + * Returns the character used to delineate multiple addresses. + * + * @param targetString + * the string to parse + * @return the character to tokenize on + */ + public static String getSeparator(String targetString) { + return OptionalUtils.or( + mayContainComma(targetString), + mayContainSemicolon(targetString), + mayContainColon(targetString)) + .orElse(""); + } + + private static Optional<String> mayContainComma(String targetString) { + return mayContain(targetString, ","); + } + + private static Optional<String> mayContainSemicolon(String targetString) { + return mayContain(targetString, ";"); + } + + private static Optional<String> mayContainColon(String targetString) { + if (Mapping.Type.hasPrefix(targetString)) { + return Optional.empty(); + } + return Optional.of(":"); + } + + private static Optional<String> mayContain(String targetString, String expectedCharacter) { + return Optional.of(expectedCharacter) + .filter(targetString::contains); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/eabfa17b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/SeparatorUtilTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-api/src/test/java/org/apache/james/rrt/lib/SeparatorUtilTest.java b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/SeparatorUtilTest.java new file mode 100644 index 0000000..7c0f520 --- /dev/null +++ b/server/data/data-api/src/test/java/org/apache/james/rrt/lib/SeparatorUtilTest.java @@ -0,0 +1,50 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.rrt.lib; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +public class SeparatorUtilTest { + + @Test + public void getSeparatorShouldReturnCommaWhenCommaIsPresent() { + String separator = SeparatorUtil.getSeparator("regex:(.*)@localhost, regex:user@test"); + assertThat(separator).isEqualTo(","); + } + + @Test + public void getSeparatorShouldReturnEmptyWhenColonIsPresentInPrefix() { + String separator = SeparatorUtil.getSeparator("regex:(.*)@localhost"); + assertThat(separator).isEqualTo(""); + } + + @Test + public void getSeparatorShouldReturnEmptyWhenColonIsPresent() { + String separator = SeparatorUtil.getSeparator("(.*)@localhost: user@test"); + assertThat(separator).isEqualTo(":"); + } + + @Test + public void getSeparatorShouldReturnColonWhenNoSeparator() { + String separator = SeparatorUtil.getSeparator("user@test"); + assertThat(separator).isEqualTo(":"); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/eabfa17b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java ---------------------------------------------------------------------- diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java deleted file mode 100644 index c633307..0000000 --- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/MappingsImpl.java +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.james.rrt.lib; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.Optional; -import java.util.StringTokenizer; -import java.util.function.Predicate; -import java.util.stream.Stream; - -import org.apache.james.rrt.lib.Mapping.Type; - -import com.github.steveash.guavate.Guavate; -import com.google.common.base.Joiner; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -public class MappingsImpl implements Mappings, Serializable { - - private static final long serialVersionUID = 1L; - - private static class DefaultMappingOrderingPolicy { - - private static final Comparator<Mapping> MAPPING_COMPARATOR = Comparator - .<Mapping, Integer>comparing(DefaultMappingOrderingPolicy::typeOrder) - .thenComparing(Mapping::asString); - - private static int typeOrder(Mapping mapping) { - return typeOrder(mapping.getType()); - } - - private static int typeOrder(Mapping.Type type) { - switch (type) { - case Domain: - return 1; - case Group: - return 2; - case Forward: - return 3; - case Regex: - return 4; - case Error: - return 4; - case Address: - return 4; - } - throw new IllegalArgumentException("missing enum handling"); - } - - public Comparator<Mapping> comparator() { - return MAPPING_COMPARATOR; - } - } - - - - public static MappingsImpl empty() { - return builder().build(); - } - - public static MappingsImpl fromRawString(String raw) { - return fromCollection(mappingToCollection(raw)); - } - - public static MappingsImpl fromMappings(Mapping... mappings) { - return fromMappings(Arrays.stream(mappings)); - } - - private static ArrayList<String> mappingToCollection(String rawMapping) { - ArrayList<String> map = new ArrayList<>(); - StringTokenizer tokenizer = new StringTokenizer(rawMapping, RecipientRewriteTableUtil.getSeparator(rawMapping)); - while (tokenizer.hasMoreTokens()) { - final String raw = tokenizer.nextToken().trim(); - map.add(raw); - } - return map; - } - - public static MappingsImpl fromCollection(Collection<String> mappings) { - return fromMappings(mappings.stream() - .map(Mapping::of)); - } - - public static MappingsImpl fromMappings(Stream<Mapping> mappings) { - return mappings - .reduce(builder(), Builder::add, Builder::merge) - .build(); - } - - public static Builder from(Mappings from) { - Builder builder = new Builder(); - builder.addAll(from); - return builder; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - public static Builder merge(Builder builder1, Builder builder2) { - return builder1.addAll(builder2.build()); - } - - private final ImmutableList.Builder<Mapping> mappings; - - private Builder() { - mappings = ImmutableList.builder(); - } - - public Builder add(String mapping) { - return add(Mapping.of(mapping)); - } - - public Builder add(Mapping mapping) { - mappings.add(mapping); - return this; - } - - public Builder addAll(Mappings mappings) { - this.mappings.addAll(mappings); - return this; - } - - public Builder addAll(Iterable<String> mappings) { - mappings.forEach(this::add); - return this; - } - - public MappingsImpl build() { - return new MappingsImpl(mappings.build() - .stream() - .sorted(new DefaultMappingOrderingPolicy().comparator()) - .collect(Guavate.toImmutableList())); - } - - } - - private final ImmutableList<Mapping> mappings; - - private MappingsImpl(Collection<Mapping> mappings) { - this.mappings = ImmutableList.copyOf(mappings); - } - - @Override - public Iterable<String> asStrings() { - return mappings.stream() - .map(Mapping::asString) - .collect(Guavate.toImmutableList()); - } - - @Override - public boolean contains(Mapping mapping) { - return mappings.contains(mapping); - } - - @Override - public int size() { - return mappings.size(); - } - - @Override - public Mappings remove(Mapping mapping) { - if (mappings.contains(mapping)) { - ArrayList<Mapping> updatedMappings = Lists.newArrayList(mappings); - updatedMappings.remove(mapping); - return new MappingsImpl(updatedMappings); - } - return this; - } - - @Override - public boolean isEmpty() { - return mappings.isEmpty(); - } - - @Override - public Iterator<Mapping> iterator() { - return mappings.iterator(); - } - - @Override - public String serialize() { - return Joiner.on(';').join(asStrings()); - } - - private Predicate<Mapping> hasType(final Mapping.Type type) { - return mapping -> mapping.getType().equals(type); - } - - @Override - public boolean contains(Type type) { - Preconditions.checkNotNull(type); - return mappings.stream() - .anyMatch(hasType(type)); - } - - @Override - public Mappings select(Type type) { - Preconditions.checkNotNull(type); - return fromMappings(mappings.stream() - .filter(hasType(type))); - } - - - @Override - public Mappings exclude(Type type) { - Preconditions.checkNotNull(type); - return fromMappings(mappings.stream() - .filter(hasType(type).negate())); - } - - @Override - public Mapping getError() { - Mappings errors = select(Type.Error); - Preconditions.checkState(!errors.isEmpty()); - return Iterables.getFirst(errors, null); - } - - @Override - public Optional<Mappings> toOptional() { - if (isEmpty()) { - return Optional.empty(); - } - return Optional.of(this); - } - - @Override - public Mappings union(Mappings mappings) { - Preconditions.checkState(mappings != null, "mappings is mandatory"); - return from(this).addAll(mappings).build(); - } - - @Override - public Stream<Mapping> asStream() { - return mappings.stream(); - } - - @Override - public int hashCode() { - return Objects.hashCode(mappings); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof MappingsImpl) { - MappingsImpl other = (MappingsImpl) obj; - return Objects.equal(mappings, other.mappings); - } - return false; - } - - @Override - public String toString() { - return "MappingsImpl{" + - "mappings=" + mappings + - '}'; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/eabfa17b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java ---------------------------------------------------------------------- diff --git a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java index 6de8378..ee51dcb 100644 --- a/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java +++ b/server/data/data-library/src/main/java/org/apache/james/rrt/lib/RecipientRewriteTableUtil.java @@ -25,7 +25,6 @@ import java.util.Optional; import java.util.StringTokenizer; import org.apache.james.core.Domain; -import org.apache.james.rrt.lib.Mapping.Type; import org.apache.james.util.OptionalUtils; /** @@ -54,41 +53,6 @@ public class RecipientRewriteTableUtil { } /** - * Returns the character used to delineate multiple addresses. - * - * @param targetString - * the string to parse - * @return the character to tokenize on - */ - public static String getSeparator(String targetString) { - return OptionalUtils.or( - mayContainComma(targetString), - mayContainSemicolon(targetString), - mayContainColon(targetString)) - .orElse(""); - } - - private static Optional<String> mayContainComma(String targetString) { - return mayContain(targetString, ","); - } - - private static Optional<String> mayContainSemicolon(String targetString) { - return mayContain(targetString, ";"); - } - - private static Optional<String> mayContainColon(String targetString) { - if (Type.hasPrefix(targetString)) { - return Optional.empty(); - } - return Optional.of(":"); - } - - private static Optional<String> mayContain(String targetString, String expectedCharacter) { - return Optional.of(expectedCharacter) - .filter(targetString::contains); - } - - /** * Returns a Map which contains the mappings * * @param mapping http://git-wip-us.apache.org/repos/asf/james-project/blob/eabfa17b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RecipientRewriteTableUtilTest.java ---------------------------------------------------------------------- diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RecipientRewriteTableUtilTest.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RecipientRewriteTableUtilTest.java deleted file mode 100644 index 2fc8384..0000000 --- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RecipientRewriteTableUtilTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ -package org.apache.james.rrt.lib; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; - -public class RecipientRewriteTableUtilTest { - - @Test - public void getSeparatorShouldReturnCommaWhenCommaIsPresent() { - String separator = RecipientRewriteTableUtil.getSeparator("regex:(.*)@localhost, regex:user@test"); - assertThat(separator).isEqualTo(","); - } - - @Test - public void getSeparatorShouldReturnEmptyWhenColonIsPresentInPrefix() { - String separator = RecipientRewriteTableUtil.getSeparator("regex:(.*)@localhost"); - assertThat(separator).isEqualTo(""); - } - - @Test - public void getSeparatorShouldReturnEmptyWhenColonIsPresent() { - String separator = RecipientRewriteTableUtil.getSeparator("(.*)@localhost: user@test"); - assertThat(separator).isEqualTo(":"); - } - - @Test - public void getSeparatorShouldReturnColonWhenNoSeparator() { - String separator = RecipientRewriteTableUtil.getSeparator("user@test"); - assertThat(separator).isEqualTo(":"); - } -} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
