|
| 1 | +/* |
| 2 | + * Copyright (c) 2018 Wave Software |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package pl.wavesoftware.eid.impl; |
| 18 | + |
| 19 | +import org.junit.After; |
| 20 | +import org.junit.Before; |
| 21 | +import org.junit.Test; |
| 22 | +import pl.wavesoftware.eid.Eid; |
| 23 | +import pl.wavesoftware.eid.configuration.Configuration; |
| 24 | +import pl.wavesoftware.eid.configuration.ConfigurationBuilder; |
| 25 | +import pl.wavesoftware.eid.configuration.Configurator; |
| 26 | +import pl.wavesoftware.eid.configuration.Formatter; |
| 27 | +import pl.wavesoftware.eid.configuration.UniqueIdGenerator; |
| 28 | + |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; |
| 30 | + |
| 31 | +/** |
| 32 | + * @author <a href="mailto:krzysztof.suszynski@wavesoftware.pl">Krzysztof Suszynski</a> |
| 33 | + * @since 2018-12-03 |
| 34 | + */ |
| 35 | +public class DefaultFormatterTest { |
| 36 | + |
| 37 | + private Configurator restore; |
| 38 | + |
| 39 | + @Before |
| 40 | + public void before() { |
| 41 | + restore = Eid.getBinding().getConfigurationSystem().configure(new Configurator() { |
| 42 | + @Override |
| 43 | + public void configure(ConfigurationBuilder configuration) { |
| 44 | + configuration.uniqueIdGenerator(new UniqueIdGenerator() { |
| 45 | + @Override |
| 46 | + public String generateUniqId() { |
| 47 | + return "deadcafe"; |
| 48 | + } |
| 49 | + }); |
| 50 | + } |
| 51 | + }); |
| 52 | + } |
| 53 | + |
| 54 | + @After |
| 55 | + public void after() { |
| 56 | + Eid.getBinding().getConfigurationSystem().configure(restore); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void format() { |
| 61 | + // given |
| 62 | + Configuration configuration = new ConfigurationImpl(); |
| 63 | + Formatter formatter = new DefaultFormatter(configuration); |
| 64 | + |
| 65 | + // when |
| 66 | + String formatted = formatter.format(new Eid("20181203:224055")); |
| 67 | + |
| 68 | + // then |
| 69 | + assertThat(formatted).isEqualTo("[20181203:224055]<deadcafe>"); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void formatWithMessage() { |
| 74 | + // given |
| 75 | + Configuration configuration = new ConfigurationImpl(); |
| 76 | + Formatter formatter = new DefaultFormatter(configuration); |
| 77 | + |
| 78 | + // when |
| 79 | + String formatted = formatter.format( |
| 80 | + new Eid("20181203:224137"), |
| 81 | + "a message" |
| 82 | + ); |
| 83 | + |
| 84 | + // then |
| 85 | + assertThat(formatted).isEqualTo("[20181203:224137]<deadcafe> => a message"); |
| 86 | + } |
| 87 | +} |
0 commit comments