2323import java .io .IOException ;
2424import java .net .URISyntaxException ;
2525import java .net .URL ;
26+ import java .nio .file .Files ;
2627import java .nio .file .Paths ;
2728import org .junit .Test ;
2829import org .junit .runner .RunWith ;
@@ -41,12 +42,11 @@ public class CreateSchemaBundleRequestTest {
4142
4243 @ Test
4344 public void testToProto () throws IOException , URISyntaxException {
44- ClassLoader cl = Thread .currentThread ().getContextClassLoader ();
45- URL protoSchema = cl .getResource (TEST_PROTO_SCHEMA_BUNDLE );
46-
4745 CreateSchemaBundleRequest request =
4846 CreateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
49- .setProtoSchema (Paths .get (protoSchema .toURI ()).toAbsolutePath ().toString ());
47+ .setProtoSchema (getResourceFilePath (TEST_PROTO_SCHEMA_BUNDLE ));
48+
49+ byte [] content = Files .readAllBytes (Paths .get (getResourceFilePath (TEST_PROTO_SCHEMA_BUNDLE )));
5050
5151 com .google .bigtable .admin .v2 .CreateSchemaBundleRequest requestProto =
5252 com .google .bigtable .admin .v2 .CreateSchemaBundleRequest .newBuilder ()
@@ -56,46 +56,52 @@ public void testToProto() throws IOException, URISyntaxException {
5656 com .google .bigtable .admin .v2 .SchemaBundle .newBuilder ()
5757 .setProtoSchema (
5858 com .google .bigtable .admin .v2 .ProtoSchema .newBuilder ()
59- .setProtoDescriptors (ByteString .copyFromUtf8 ( "schema" ))
59+ .setProtoDescriptors (ByteString .copyFrom ( content ))
6060 .build ())
6161 .build ())
6262 .build ();
6363 assertThat (request .toProto (PROJECT_ID , INSTANCE_ID )).isEqualTo (requestProto );
6464 }
6565
6666 @ Test
67- public void testEquality () throws IOException {
67+ public void testEquality () throws IOException , URISyntaxException {
6868 CreateSchemaBundleRequest request =
6969 CreateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
70- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE );
70+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) );
7171
7272 assertThat (request )
7373 .isEqualTo (
7474 CreateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
75- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE ));
75+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) ));
7676
7777 assertThat (request )
7878 .isNotEqualTo (
7979 CreateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
80- .setProtoSchema (TEST_UPDATED_PROTO_SCHEMA_BUNDLE ));
80+ .setProtoSchema (getResourceFilePath ( TEST_UPDATED_PROTO_SCHEMA_BUNDLE ) ));
8181 }
8282
8383 @ Test
84- public void testHashCode () throws IOException {
84+ public void testHashCode () throws IOException , URISyntaxException {
8585 CreateSchemaBundleRequest request =
8686 CreateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
87- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE );
87+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) );
8888
8989 assertThat (request .hashCode ())
9090 .isEqualTo (
9191 CreateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
92- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE )
92+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) )
9393 .hashCode ());
9494
9595 assertThat (request .hashCode ())
9696 .isNotEqualTo (
9797 CreateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
98- .setProtoSchema (TEST_UPDATED_PROTO_SCHEMA_BUNDLE )
98+ .setProtoSchema (getResourceFilePath ( TEST_UPDATED_PROTO_SCHEMA_BUNDLE ) )
9999 .hashCode ());
100100 }
101+
102+ private String getResourceFilePath (String filePath ) throws URISyntaxException {
103+ ClassLoader cl = Thread .currentThread ().getContextClassLoader ();
104+ URL protoSchema = cl .getResource (filePath );
105+ return Paths .get (protoSchema .toURI ()).toAbsolutePath ().toString ();
106+ }
101107}
0 commit comments