View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.io.build;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  
22  import org.junit.jupiter.api.Test;
23  
24  /**
25   * Tests {@link AbstractSupplier}.
26   * <p>
27   * This code is used in Javadoc.
28   * </p>
29   */
30  class AbstractSupplierTest {
31  
32      /**
33       * Builds {@link Foo} instances.
34       */
35      public static class Builder extends AbstractSupplier<Foo, Builder> {
36  
37          private String bar1;
38          private String bar2;
39          private String bar3;
40  
41          /**
42           * Builds a new {@link Foo}.
43           */
44          @Override
45          public Foo get() {
46              return new Foo(bar1, bar2, bar3);
47          }
48  
49          public Builder setBar1(final String bar1) {
50              this.bar1 = bar1;
51              return this;
52          }
53  
54          public Builder setBar2(final String bar2) {
55              this.bar2 = bar2;
56              return this;
57          }
58  
59          public Builder setBar3(final String bar3) {
60              this.bar3 = bar3;
61              return this;
62          }
63      }
64  
65      /**
66       * Domain class.
67       */
68      public static class Foo {
69  
70          public static Builder builder() {
71              return new Builder();
72          }
73  
74          private final String bar1;
75          private final String bar2;
76          private final String bar3;
77  
78          private Foo(final String bar1, final String bar2, final String bar3) {
79              this.bar1 = bar1;
80              this.bar2 = bar2;
81              this.bar3 = bar3;
82          }
83  
84          public String getBar1() {
85              return bar1;
86          }
87  
88          public String getBar2() {
89              return bar2;
90          }
91  
92          public String getBar3() {
93              return bar3;
94          }
95  
96      }
97  
98      @Test
99      void test() {
100         // @formatter:off
101         final Foo foo = Foo.builder()
102             .setBar1("value1")
103             .setBar2("value2")
104             .setBar3("value3")
105             .get();
106         // @formatter:on
107         assertEquals("value1", foo.getBar1());
108         assertEquals("value2", foo.getBar2());
109         assertEquals("value3", foo.getBar3());
110     }
111 }