Java tutorial
/* * The MIT License (MIT) * * Copyright (c) 2015 Kunal Shah * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package com.codepine.api.testrail.model; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.google.common.base.Objects; import lombok.Data; import java.util.Collections; import java.util.HashMap; import java.util.Map; /** * TestRail test. */ @Data public class Test { private static final String CUSTOM_FIELD_KEY_PREFIX = "custom_"; private int id; private int caseId; private Integer assignedtoId; private String title; private int statusId; private int typeId; private int priorityId; private Integer milestoneId; private Integer runId; private String refs; private String estimate; private String estimateForecast; private Map<String, Object> customFields; public Map<String, Object> getCustomFields() { return Objects.firstNonNull(customFields, Collections.<String, Object>emptyMap()); } /** * Add a custom field. * * @param key the name of the custom field with or without "custom_" prefix * @param value the value of the custom field * @return test instance for chaining */ public Test addCustomField(String key, Object value) { if (customFields == null) { customFields = new HashMap<>(); } customFields.put(key.replaceFirst(CUSTOM_FIELD_KEY_PREFIX, ""), value); return this; } /** * Support for forward compatibility and extracting custom fields. * * @param key the name of the unknown field * @param value the value of the unkown field */ @JsonAnySetter private void addUnknownField(String key, Object value) { if (key.startsWith(CUSTOM_FIELD_KEY_PREFIX)) { addCustomField(key, value); } } }