001/* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 015package org.basepom.mojo.propertyhelper.definitions; 016 017import static org.junit.jupiter.api.Assertions.assertThrows; 018 019import org.basepom.mojo.propertyhelper.Field; 020import org.basepom.mojo.propertyhelper.FieldContext; 021import org.basepom.mojo.propertyhelper.ValueCache; 022 023import java.util.UUID; 024 025import org.junit.jupiter.api.Assertions; 026import org.junit.jupiter.api.Test; 027 028 029public class TestElementDefinition { 030 031 @Test 032 public void testValidId() { 033 final BasicDefinition fieldDefinition = new BasicDefinition(); 034 035 fieldDefinition.id = "hello"; 036 fieldDefinition.check(); 037 } 038 039 @Test 040 public void testUnsetId() { 041 assertThrows(IllegalStateException.class, () -> { 042 final BasicDefinition fieldDefinition = new BasicDefinition(); 043 fieldDefinition.check(); 044 }); 045 } 046 047 @Test 048 public void testBlankId() { 049 assertThrows(IllegalStateException.class, () -> { 050 final BasicDefinition fieldDefinition = new BasicDefinition(); 051 fieldDefinition.check(); 052 }); 053 } 054 055 @Test 056 public void testDefaults() { 057 final String id = UUID.randomUUID().toString(); 058 final BasicDefinition fieldDefinition = new BasicDefinition(); 059 fieldDefinition.id = id; 060 fieldDefinition.check(); 061 Assertions.assertEquals(id, fieldDefinition.getId()); 062 Assertions.assertFalse(fieldDefinition.isSkip()); 063 } 064 065 public static class BasicDefinition extends FieldDefinition<String> { 066 067 public BasicDefinition() { 068 } 069 070 @Override 071 public Field<String, BasicDefinition> createField(FieldContext context, ValueCache valueCache) { 072 throw new UnsupportedOperationException(); 073 } 074 } 075}