Skip to content

Commit

Permalink
[3.x] WritableMultiPart create methods fixed (#6390)
Browse files Browse the repository at this point in the history
WritableMultiPart create methods fixed

Signed-off-by: David Kral <[email protected]>
  • Loading branch information
Verdent authored Mar 9, 2023
1 parent 8aa217e commit 52d9227
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,7 +50,7 @@ public List<WriteableBodyPart> bodyParts() {
public static WriteableMultiPart create(WriteableBodyPart... entities) {
Builder builder = builder();
for (WriteableBodyPart entity : entities) {
builder.bodyPart(WriteableBodyPart.create(entity));
builder.bodyPart(entity);
}
return builder.build();
}
Expand All @@ -65,7 +65,7 @@ public static WriteableMultiPart create(WriteableBodyPart... entities) {
public static WriteableMultiPart create(Collection<WriteableBodyPart> entities) {
Builder builder = builder();
for (WriteableBodyPart entity : entities) {
builder.bodyPart(WriteableBodyPart.create(entity));
builder.bodyPart(entity);
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.media.multipart;

import java.util.List;

import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.is;

/**
* Test {@link WriteableMultiPart}.
*/
public class WritableMultiPartTest {

@Test
public void testWritableMultiPartCreation() {
WriteableBodyPart bodyPart = WriteableBodyPart.create("MyStringEntity");
List<WriteableBodyPart> expectedBodyParts = List.of(bodyPart);
WriteableMultiPart multiPart = WriteableMultiPart.create(bodyPart);
assertThat(multiPart.bodyParts(), is(expectedBodyParts));

multiPart = WriteableMultiPart.create(List.of(bodyPart));
assertThat(multiPart.bodyParts(), is(expectedBodyParts));

multiPart = WriteableMultiPart.builder()
.bodyPart(bodyPart)
.build();
assertThat(multiPart.bodyParts(), is(expectedBodyParts));
}

}

0 comments on commit 52d9227

Please sign in to comment.