001/* 002 * Copyright 2023 the original author or authors. 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.cuioss.test.valueobjects.contract.support; 017 018import static de.cuioss.tools.string.MoreStrings.emptyToNull; 019import static org.junit.jupiter.api.Assertions.assertEquals; 020import static org.junit.jupiter.api.Assertions.assertNotNull; 021 022import de.cuioss.tools.string.Splitter; 023import lombok.EqualsAndHashCode; 024import lombok.Getter; 025import lombok.NonNull; 026import lombok.ToString; 027 028/** 029 * @author Oliver Wolff 030 * 031 */ 032@EqualsAndHashCode 033@ToString 034public class MappingTuple { 035 036 @Getter 037 private final String source; 038 039 @Getter 040 private final String target; 041 042 @Getter 043 private final MappingAssertStrategy strategy; 044 045 /** 046 * @param mapping in the form "source:target". Any other String will result in 047 * an {@link AssertionError} 048 * @param strategy must not be null. Identifies the MappingAssertStrategy for 049 * this element 050 */ 051 public MappingTuple(String mapping, @NonNull MappingAssertStrategy strategy) { 052 assertNotNull(emptyToNull(mapping), "Mapping must not be null"); 053 var splitted = Splitter.on(':').splitToList(mapping); 054 assertEquals(2, splitted.size(), "Expected a String in the form of 'source:target' but was: " + mapping); 055 source = splitted.get(0); 056 target = splitted.get(1); 057 this.strategy = strategy; 058 } 059}