Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,36 @@
<spotless.config.path>../</spotless.config.path>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-eclipse-format-settings</id>
<phase>generate-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/test-classes</outputDirectory>
<resources>
<resource>
<directory>../</directory>
<includes>
<include>eclipse-format-azure-sdk-for-java.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>io.clientcore</groupId>
Expand Down Expand Up @@ -171,5 +201,11 @@
<version>5.13.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.13.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.typespec.http.client.generator.core.postprocessor.implementation;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class CodeFormatterUtilTests {
@ParameterizedTest
@ValueSource(strings = { "module-info.java", "src/main/module-info.java" })
public void moduleInfoFormatting(String fileName) {
String initial = String.join("\n", "// Copyright (c) Microsoft Corporation. All rights reserved.",
"// Licensed under the MIT License.", "// Code generated by Microsoft (R) TypeSpec Code Generator.", "",
"module com.azure.resourcemanager.avs {", "requires transitive com.azure.core.management;",
"exports com.azure.resourcemanager.avs;", "exports com.azure.resourcemanager.avs.fluent;",
"exports com.azure.resourcemanager.avs.fluent.models;", "exports com.azure.resourcemanager.avs.models;",
"opens com.azure.resourcemanager.avs.fluent.models", "to com.azure.core;",
"opens com.azure.resourcemanager.avs.models", "to com.azure.core;",
"opens com.azure.resourcemanager.avs.implementation.models to com.azure.core;", "}");
String expected = String.join("\n", "// Copyright (c) Microsoft Corporation. All rights reserved.",
"// Licensed under the MIT License.", "// Code generated by Microsoft (R) TypeSpec Code Generator.", "",
"module com.azure.resourcemanager.avs {", " requires transitive com.azure.core.management;", "",
" exports com.azure.resourcemanager.avs;", " exports com.azure.resourcemanager.avs.fluent;",
" exports com.azure.resourcemanager.avs.fluent.models;",
" exports com.azure.resourcemanager.avs.models;", "",
" opens com.azure.resourcemanager.avs.fluent.models to com.azure.core;",
" opens com.azure.resourcemanager.avs.models to com.azure.core;",
" opens com.azure.resourcemanager.avs.implementation.models to com.azure.core;", "}", "");

List<String> formattingResult = CodeFormatterUtil.formatCode(new HashMap<>(Map.of(fileName, initial)));

assertEquals(1, formattingResult.size());
assertEquals(expected, formattingResult.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public void testJsonFromEnumType() {
.build();

Object jsonObject = ModelTestCaseUtil.jsonFromType(0, type);
Assertions.assertTrue(jsonObject instanceof String);
Assertions.assertInstanceOf(String.class, jsonObject);
Assertions.assertTrue(Objects.equals("200", jsonObject) || Objects.equals("404", jsonObject));

type = new EnumType.Builder().elementType(ClassType.INTEGER)
.values(Arrays.asList(new ClientEnumValue("200", "200"), new ClientEnumValue("404", "404")))
.build();

jsonObject = ModelTestCaseUtil.jsonFromType(0, type);
Assertions.assertTrue(jsonObject instanceof Integer);
Assertions.assertInstanceOf(Integer.class, jsonObject);
Assertions.assertTrue(Objects.equals(200, jsonObject) || Objects.equals(404, jsonObject));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ public void testObjectSchemaFindParent() {
Assertions.assertEquals(PET, SchemaUtil.getLowestCommonParent(List.of(CAT, DOG, CORGI)));
ObjectSchema dummy = new ObjectSchema();
dummy.set$key("dummy");
Assertions.assertTrue(SchemaUtil.getLowestCommonParent(List.of(dummy, DOG)) instanceof AnySchema);
Assertions.assertInstanceOf(AnySchema.class, SchemaUtil.getLowestCommonParent(List.of(dummy, DOG)));
}

@Test
public void testAllSchemaFindParent() {
Assertions.assertTrue(SchemaUtil.getLowestCommonParent(List.of(new ArraySchema(), PET)) instanceof AnySchema);
Assertions
.assertTrue(SchemaUtil.getLowestCommonParent(List.of(new DictionarySchema(), PET)) instanceof AnySchema);
Assertions.assertInstanceOf(AnySchema.class, SchemaUtil.getLowestCommonParent(List.of(new ArraySchema(), PET)));
Assertions.assertInstanceOf(AnySchema.class,
SchemaUtil.getLowestCommonParent(List.of(new DictionarySchema(), PET)));
StringSchema stringSchema = new StringSchema();
Assertions.assertTrue(SchemaUtil.getLowestCommonParent(List.of(stringSchema)) instanceof StringSchema);
Assertions
.assertTrue(SchemaUtil.getLowestCommonParent(List.of(stringSchema, stringSchema)) instanceof StringSchema);
Assertions.assertInstanceOf(StringSchema.class, SchemaUtil.getLowestCommonParent(List.of(stringSchema)));
Assertions.assertInstanceOf(StringSchema.class,
SchemaUtil.getLowestCommonParent(List.of(stringSchema, stringSchema)));
}
}
8 changes: 8 additions & 0 deletions packages/http-client-java/generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
</systemPropertyVariables>
<forkCount>1</forkCount>
<testFailureIgnore>false</testFailureIgnore>
<argLine>
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
</argLine>
</configuration>
</plugin>

Expand Down
Loading