1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.api.plugin.descriptor.another;
20
21 import org.apache.maven.api.plugin.descriptor.PluginDescriptor;
22 import org.junit.jupiter.api.Test;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25
26 /**
27 * Verifies that subclasses from generated model classes are possible.
28 */
29 class ExtendedPluginDescriptorTest {
30
31 /**
32 * A subclass of the generated class {@link PluginDescriptor} that adds an additional field.
33 */
34 static class ExtendedPluginDescriptor extends PluginDescriptor {
35
36 private final String additionalField;
37
38 ExtendedPluginDescriptor(Builder builder) {
39 super(builder);
40 this.additionalField = builder.additionalField;
41 }
42
43 public String getAdditionalField() {
44 return additionalField;
45 }
46
47 static class Builder extends PluginDescriptor.Builder {
48 protected String additionalField;
49
50 Builder() {
51 super(false);
52 }
53
54 public Builder additionalField(String additionalField) {
55 this.additionalField = additionalField;
56 return this;
57 }
58
59 @Override
60 public ExtendedPluginDescriptor build() {
61 return new ExtendedPluginDescriptor(this);
62 }
63 }
64 }
65
66 @Test
67 void testExtendedPluginDescriptor() {
68 ExtendedPluginDescriptor.Builder builder = new ExtendedPluginDescriptor.Builder();
69 // make sure to call the subclasses' builder methods first, otherwise fluent API would not work
70 builder.additionalField("additional")
71 .groupId("org.apache.maven")
72 .artifactId("maven-plugin-api")
73 .version("1.0.0");
74 ExtendedPluginDescriptor descriptor = builder.build();
75 assertEquals("additional", descriptor.getAdditionalField());
76 assertEquals("org.apache.maven", descriptor.getGroupId());
77 }
78 }