org.junit.experimental.theories.Theory Java Examples
The following examples show how to use
org.junit.experimental.theories.Theory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BuildApksDeviceSpecTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test @Theory public void deviceSpec_systemApkMode_partialDeviceSpecMissingDensity_throws( @FromDataPoints("systemApkBuildModes") ApkBuildMode systemApkBuildMode) throws Exception { DeviceSpec deviceSpec = mergeSpecs(abis("arm64-v8a")); AppBundle appBundle = new AppBundleBuilder() .addModule("base", module -> module.setManifest(androidManifest("com.app"))) .build(); bundleSerializer.writeToDisk(appBundle, bundlePath); BuildApksCommand.Builder command = BuildApksCommand.builder() .setBundlePath(bundlePath) .setOutputFile(outputFilePath) .setDeviceSpec(deviceSpec) .setApkBuildMode(systemApkBuildMode); Throwable exception = assertThrows(InvalidCommandException.class, command::build); assertThat(exception) .hasMessageThat() .contains( "Device spec must have screen density and ABIs set when running with 'system' or " + "'system_compressed' mode flag."); }
Example #2
Source File: RegisterPeerActionTest.java From emissary with Apache License 2.0 | 6 votes |
@Theory public void badParamValues(String badValue) { // setup formParams.replace(DIRECTORY_NAME, Arrays.asList(badValue)); formParams.replace(TARGET_DIRECTORY, Arrays.asList(badValue)); // test Response response = target(REGISTER_PEER_ACTION).request().post(Entity.form(formParams)); // verify final int status = response.getStatus(); assertThat(status, equalTo(500)); final String result = response.readEntity(String.class); assertThat(result.startsWith("Bad Params: "), equalTo(true)); }
Example #3
Source File: BuildApksDeviceSpecTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test @Theory public void deviceSpec_systemApkMode_partialDeviceSpecWithAbiAndScreenDensity_succeeds( @FromDataPoints("systemApkBuildModes") ApkBuildMode systemApkBuildMode) throws Exception { DeviceSpec deviceSpec = mergeSpecs(abis("arm64-v8a"), density(DensityAlias.MDPI)); AppBundle appBundle = new AppBundleBuilder() .addModule("base", module -> module.setManifest(androidManifest("com.app"))) .build(); bundleSerializer.writeToDisk(appBundle, bundlePath); BuildApksCommand.Builder command = BuildApksCommand.builder() .setBundlePath(bundlePath) .setOutputFile(outputFilePath) .setDeviceSpec(deviceSpec) .setApkBuildMode(systemApkBuildMode); command.build(); }
Example #4
Source File: TestCaseFinderJunitVintageTheoryTest.java From recheck with GNU Affero General Public License v3.0 | 6 votes |
@Theory public void junit_vintage_theory_annotation_should_be_found( final int count ) throws Exception { final String expectedClassName = getClass().getName(); final String expectedMethodName = "junit_vintage_theory_annotation_should_be_found"; final TestCaseAnnotationType expectedType = TestCaseAnnotationType.REPEATABLE; final int expectedInvocationCount = count; final Optional<String> actualClassName = TestCaseFinder.getInstance().findTestCaseClassNameInStack(); assertThat( actualClassName ).hasValue( expectedClassName ); final Optional<String> actualMethodName = TestCaseFinder.getInstance().findTestCaseMethodNameInStack(); assertThat( actualMethodName ).hasValueSatisfying( methodName -> methodName.startsWith( expectedMethodName ) ); final TestCaseInformation info = TestCaseFinder.getInstance().findTestCaseMethodInStack(); assertThat( info.getStackTraceElement().getClassName() ).isEqualTo( expectedClassName ); assertThat( info.getStackTraceElement().getMethodName() ).isEqualTo( expectedMethodName ); assertThat( info.getTestCaseAnnotationType() ).isEqualTo( expectedType ); assertThat( info.getInvocationCount() ).isEqualTo( expectedInvocationCount ); }
Example #5
Source File: WorkBundleCompletedActionTest.java From emissary with Apache License 2.0 | 6 votes |
@Theory public void emptyParams(String badValue) { // setup formParams.replace(CLIENT_NAME, Arrays.asList(badValue)); formParams.replace(SPACE_NAME, Arrays.asList(badValue)); formParams.replace(WORK_BUNDLE_ID, Arrays.asList(badValue)); formParams.replace(WORK_BUNDLE_STATUS, Arrays.asList(badValue)); // test final Response response = target(WORK_BUNDLE_COMPLETED_ACTION).request().post(Entity.form(formParams)); // verify final int status = response.getStatus(); assertThat(status, equalTo(500)); final String result = response.readEntity(String.class); assertThat(result.startsWith("Bad params:"), equalTo(true)); }
Example #6
Source File: CreatePlaceActionTest.java From emissary with Apache License 2.0 | 6 votes |
@Theory public void testCreatePlaceBadParams(String badParam) { // This causes 500 errors because we are posting with empty required parameters // setup formParams = new MultivaluedHashMap<>(); formParams.put(CP_DIRECTORY, Arrays.asList(badParam)); formParams.put(CP_LOCATION, Arrays.asList(badParam)); formParams.put(CP_CLASS_NAME, Arrays.asList(badParam)); // test Response response = target(CREATE_PLACE_ACTION).request().post(Entity.form(formParams)); // verify final int status = response.getStatus(); assertThat(status, equalTo(500)); final String result = response.readEntity(String.class); assertThat(result, equalTo(CreatePlaceAction.EMPTY_PARAM_MSG)); }
Example #7
Source File: BuildApksDeviceSpecTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test @Theory public void deviceSpec_systemApkMode_partialDeviceSpecMissingAbi_throws( @FromDataPoints("systemApkBuildModes") ApkBuildMode systemApkBuildMode) throws Exception { DeviceSpec deviceSpec = mergeSpecs(density(DensityAlias.MDPI)); AppBundle appBundle = new AppBundleBuilder() .addModule("base", module -> module.setManifest(androidManifest("com.app"))) .build(); bundleSerializer.writeToDisk(appBundle, bundlePath); BuildApksCommand.Builder command = BuildApksCommand.builder() .setBundlePath(bundlePath) .setOutputFile(outputFilePath) .setDeviceSpec(deviceSpec) .setApkBuildMode(systemApkBuildMode); Throwable exception = assertThrows(InvalidCommandException.class, command::build); assertThat(exception) .hasMessageThat() .contains( "Device spec must have screen density and ABIs set when running with 'system' or " + "'system_compressed' mode flag."); }
Example #8
Source File: BuildApksDeviceSpecTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test @Theory public void deviceSpec_systemApkMode_withoutDeviceSpec_throws( @FromDataPoints("systemApkBuildModes") ApkBuildMode systemApkBuildMode) throws Exception { AppBundle appBundle = new AppBundleBuilder() .addModule("base", module -> module.setManifest(androidManifest("com.app"))) .build(); bundleSerializer.writeToDisk(appBundle, bundlePath); BuildApksCommand.Builder command = BuildApksCommand.builder() .setBundlePath(bundlePath) .setOutputFile(outputFilePath) .setApkBuildMode(systemApkBuildMode); Throwable exception = assertThrows(InvalidCommandException.class, command::build); assertThat(exception) .hasMessageThat() .contains( "Device spec must always be set when running with 'system' or 'system_compressed' " + "mode flag."); }
Example #9
Source File: AttributeImplTest.java From recheck with GNU Affero General Public License v3.0 | 6 votes |
@Theory public void applyVariableChange_should_return_same_attribute_type( final Attribute attribute ) { if ( attribute instanceof ParameterizedAttribute ) { final ParameterizedAttribute param = (ParameterizedAttribute) attribute; final ParameterizedAttribute changed1 = param.applyVariableChange( "new-variable" ); assertThat( changed1 ).hasSameClassAs( attribute ); assertThat( changed1.getVariableName() ).isEqualTo( "new-variable" ); assertThat( changed1.getValue() ).isEqualTo( param.getValue() ); final ParameterizedAttribute changed2 = (ParameterizedAttribute) changed1.applyChanges( valueChange.get( attribute ) ); assertThat( changed2.getVariableName() ).isEqualTo( changed1.getVariableName() ); } }
Example #10
Source File: GetSizeCommandTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test @Theory public void checkFlagsConstructionWithDeviceSpec( @FromDataPoints("deviceSpecs") String deviceSpecPath) throws Exception { DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder(); try (Reader reader = TestData.openReader(deviceSpecPath)) { JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder); } DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build(); BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance(); Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks")); Path deviceSpecFile = copyToTempDir(deviceSpecPath); GetSizeCommand command = GetSizeCommand.fromFlags( new FlagParser() .parse( "get-size", "total", "--device-spec=" + deviceSpecFile, "--apks=" + apksArchiveFile)); assertThat(command.getDeviceSpec()).isEqualTo(expectedDeviceSpec); }
Example #11
Source File: FeedCommandIT.java From emissary with Apache License 2.0 | 6 votes |
@Theory public void verifyExpectedOptions(@FromDataPoints("ProjectBase Options") String baseDirArg, @FromDataPoints("Input Options") String inputDirArg, @FromDataPoints("String Options") String stringArg, @FromDataPoints("Boolean Options") String booleanArg, @FromDataPoints("Int Options") String intArg) throws Exception { // setup arguments.add(baseDirArg); arguments.add(baseDir.toString()); arguments.add(inputDirArg); arguments.add(inputDir.toString()); arguments.add(stringArg); arguments.add("validateStringArg"); arguments.add(booleanArg); arguments.add(intArg); arguments.add("4"); // verify (no exceptions thrown) FeedCommand.parse(FeedCommand.class, arguments); }
Example #12
Source File: AndroidManifestValidatorTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test @Theory public void assetModule_withSdkConstraint_throws( @FromDataPoints("sdkMutators") ManifestMutator sdkMutator) throws Exception { BundleModule module = new BundleModuleBuilder("asset_module") .setManifest(androidManifestForAssetModule("com.test.app", sdkMutator)) .build(); InvalidBundleException exception = assertThrows( InvalidBundleException.class, () -> new AndroidManifestValidator().validateModule(module)); assertThat(exception) .hasMessageThat() .matches("Unexpected element declaration in manifest of asset pack 'asset_module'."); }
Example #13
Source File: InstallApksCommandTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test @Theory public void badDensityDevice_throws(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception { Path apksFile = createApks(createSimpleTableOfContent(ZipPath.create("base-master.apk")), apksInDirectory); DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(-1), abis("x86_64", "x86"), locales("en-US")); FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec); AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */ true, ImmutableList.of(fakeDevice)); InstallApksCommand command = InstallApksCommand.builder() .setApksArchivePath(apksFile) .setAdbPath(adbPath) .setAdbServer(adbServer) .build(); Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute()); assertThat(exception).hasMessageThat().contains("Error retrieving device density"); }
Example #14
Source File: InstallApksCommandTest.java From bundletool with Apache License 2.0 | 6 votes |
@Test @Theory public void badAbisDevice_throws(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception { Path apksFile = createApks(createSimpleTableOfContent(ZipPath.create("base-master.apk")), apksInDirectory); DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis(), locales("en-US")); FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec); AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */ true, ImmutableList.of(fakeDevice)); InstallApksCommand command = InstallApksCommand.builder() .setApksArchivePath(apksFile) .setAdbPath(adbPath) .setAdbServer(adbServer) .build(); Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute()); assertThat(exception).hasMessageThat().contains("Error retrieving device ABIs"); }
Example #15
Source File: ConfigFileActionTest.java From emissary with Apache License 2.0 | 5 votes |
@Theory public void testCreatePlaceBadParams(String badParam) { Response response = target(CONFIG_ACTION).queryParam(CONFIG_PARAM, badParam).request().get(); assertThat(500, equalTo(response.getStatus())); String body = response.readEntity(String.class); assertThat(body, equalTo(CreatePlaceAction.EMPTY_PARAM_MSG)); }
Example #16
Source File: HeartbeatActionTest.java From emissary with Apache License 2.0 | 5 votes |
@Theory public void badParams(String badValue) { // setup formParams.put(HeartbeatAdapter.FROM_PLACE_NAME, Arrays.asList(badValue)); formParams.put(HeartbeatAdapter.TO_PLACE_NAME, Arrays.asList(badValue)); // test final Response response = target(HEARTBEAT_ACTION).request().post(Entity.form(formParams)); // verify final int status = response.getStatus(); assertThat(status, equalTo(500)); final String result = response.readEntity(String.class); assertThat(result, StringStartsWith.startsWith("Heartbeat failed")); }
Example #17
Source File: AttributeImplTest.java From recheck with GNU Affero General Public License v3.0 | 5 votes |
@Theory public void applyChange_should_not_change_variable_name( final Attribute attribute ) { if ( attribute instanceof ParameterizedAttribute ) { final ParameterizedAttribute param = (ParameterizedAttribute) attribute; final ParameterizedAttribute changed1 = param.applyVariableChange( "new-variable" ); final ParameterizedAttribute changed2 = (ParameterizedAttribute) changed1.applyChanges( valueChange.get( attribute ) ); assertThat( changed2.getVariableName() ).isEqualTo( changed1.getVariableName() ); } }
Example #18
Source File: FailDirectoryActionTest.java From emissary with Apache License 2.0 | 5 votes |
@Theory public void badParams(String badParam) { // setup formParams.replace(TARGET_DIRECTORY, Arrays.asList(badParam)); formParams.replace(ADD_KEY, Arrays.asList(badParam)); // test final Response response = target(FAIL_DIRECTORY_ACTION).request().post(Entity.form(formParams)); // verify final int status = response.getStatus(); assertThat(status, equalTo(500)); final String result = response.readEntity(String.class); assertThat(result.startsWith("Bad params:"), equalTo(true)); }
Example #19
Source File: ProtocolCompatibilityTest.java From servicetalk with Apache License 2.0 | 5 votes |
@Theory public void serviceTalkToServiceTalkError(@FromDataPoints("ssl") final boolean ssl, @FromDataPoints("streaming") final boolean streaming) throws Exception { final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE, ssl); final CompatClient client = serviceTalkClient(server.listenAddress(), ssl); testGrpcError(client, server, false, streaming); }
Example #20
Source File: AttributeImplTest.java From recheck with GNU Affero General Public License v3.0 | 5 votes |
@Theory public void applyVariableChange_should_not_change_value( final Attribute attribute ) { if ( attribute instanceof ParameterizedAttribute ) { final ParameterizedAttribute param = (ParameterizedAttribute) attribute; final ParameterizedAttribute changed1 = param.applyVariableChange( "new-variable" ); assertThat( changed1.getValue() ).isEqualTo( param.getValue() ); } }
Example #21
Source File: AttributeImplPersistenceTest.java From recheck with GNU Affero General Public License v3.0 | 5 votes |
@Theory @SuppressWarnings( { "unchecked", "rawtypes" } ) public void check_persisted_and_loaded_attribtue_should_be_same( final Attribute attribute ) throws Exception { final XmlTransformer transformer = new XmlTransformer( StdXmlClassesProvider.getXmlDataClasses( AttributeWrapper.class ) ); final String xml = transformer.toXML( new ReTestXmlDataContainer( new AttributeWrapper( attribute ) ) ); final Attribute loaded = ((ReTestXmlDataContainer<AttributeWrapper>) transformer .fromXML( new ByteArrayInputStream( xml.getBytes( "utf-8" ) ) )).data().attribute; assertThat( attribute ).isEqualTo( loaded ); assertThat( attribute.hashCode() ).isEqualTo( loaded.hashCode() ); assertThat( attribute.match( loaded ) ).isEqualTo( 1.0 ); }
Example #22
Source File: DeregisterPlaceActionTest.java From emissary with Apache License 2.0 | 5 votes |
@Theory public void badParams(String badParam) { // setup formParams.replace(TARGET_DIRECTORY, Arrays.asList(badParam)); formParams.replace(ADD_KEY, Arrays.asList(badParam)); // test final Response response = target(DEREGISTER_PLACE_ACTION).request().post(Entity.form(formParams)); // verify final int status = response.getStatus(); assertThat(status, equalTo(500)); final String result = response.readEntity(String.class); assertThat(result.startsWith("Bad params:"), equalTo(true)); }
Example #23
Source File: ExtractApksCommandTest.java From bundletool with Apache License 2.0 | 5 votes |
@Test @Theory public void oneModule_Ldevice_matchesLmasterSplit( @FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception { ZipPath apkOne = ZipPath.create("apk_one.apk"); BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder() .setBundletool( Bundletool.newBuilder() .setVersion(BundleToolVersion.getCurrentVersion().toString())) .addVariant( createVariantForSingleSplitApk( variantSdkTargeting(sdkVersionFrom(21)), ApkTargeting.getDefaultInstance(), apkOne)) .build(); Path apksPath = createApks(tableOfContentsProto, apksInDirectory); DeviceSpec deviceSpec = deviceWithSdk(21); ExtractApksCommand.Builder extractedApksCommand = ExtractApksCommand.builder().setApksArchivePath(apksPath).setDeviceSpec(deviceSpec); if (!apksInDirectory) { extractedApksCommand.setOutputDirectory(tmpDir); } ImmutableList<Path> matchedApks = extractedApksCommand.build().execute(); if (apksInDirectory) { assertThat(matchedApks).containsExactly(inTempDirectory(apkOne.toString())); } else { assertThat(matchedApks).containsExactly(inOutputDirectory(apkOne.getFileName())); } for (Path matchedApk : matchedApks) { checkFileExistsAndReadable(tmpDir.resolve(matchedApk)); } }
Example #24
Source File: WorkSpaceClientSpaceTakeActionTest.java From emissary with Apache License 2.0 | 5 votes |
@Theory public void emptyParams(String badValue) { // setup formParams.replace(CLIENT_NAME, Arrays.asList(badValue)); formParams.replace(SPACE_NAME, Arrays.asList(badValue)); // test Response response = target(CLIENT_SPACE_TAKE_ACTION).request().post(Entity.form(formParams)); // verify final int status = response.getStatus(); assertThat(status, equalTo(500)); final String result = response.readEntity(String.class); assertThat(result.startsWith("Bad params:"), equalTo(true)); }
Example #25
Source File: AttributeImplTest.java From recheck with GNU Affero General Public License v3.0 | 5 votes |
@Theory public void applyChange_should_return_same_attribute_type( final Attribute attribute ) throws Exception { final Serializable value = valueChange.get( attribute ); final Attribute changed = attribute.applyChanges( value ); assertThat( changed ).hasSameClassAs( attribute ); assertThat( changed.getValue() ).isEqualTo( value ); }
Example #26
Source File: ProtocolCompatibilityTest.java From servicetalk with Apache License 2.0 | 5 votes |
@Theory public void serviceTalkToServiceTalkErrorWithStatusViaServerFilter( @FromDataPoints("ssl") final boolean ssl, @FromDataPoints("streaming") final boolean streaming) throws Exception { final TestServerContext server = serviceTalkServer(ErrorMode.STATUS_IN_SERVER_FILTER, ssl); final CompatClient client = serviceTalkClient(server.listenAddress(), ssl); testGrpcError(client, server, true, streaming); }
Example #27
Source File: ProtocolCompatibilityTest.java From servicetalk with Apache License 2.0 | 5 votes |
@Theory public void serviceTalkToServiceTalkErrorWithStatusViaServiceFilter( @FromDataPoints("ssl") final boolean ssl, @FromDataPoints("streaming") final boolean streaming) throws Exception { final TestServerContext server = serviceTalkServer(ErrorMode.STATUS_IN_SERVICE_FILTER, ssl); final CompatClient client = serviceTalkClient(server.listenAddress(), ssl); testGrpcError(client, server, true, streaming); }
Example #28
Source File: ProtocolCompatibilityTest.java From servicetalk with Apache License 2.0 | 5 votes |
@Theory public void serviceTalkToServiceTalkErrorWithStatus(@FromDataPoints("ssl") final boolean ssl, @FromDataPoints("streaming") final boolean streaming) throws Exception { final TestServerContext server = serviceTalkServer(ErrorMode.STATUS, ssl); final CompatClient client = serviceTalkClient(server.listenAddress(), ssl); testGrpcError(client, server, true, streaming); }
Example #29
Source File: ProtocolCompatibilityTest.java From servicetalk with Apache License 2.0 | 5 votes |
@Theory public void serviceTalkToServiceTalkErrorViaServerFilter(@FromDataPoints("ssl") final boolean ssl, @FromDataPoints("streaming") final boolean streaming) throws Exception { final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE_IN_SERVER_FILTER, ssl); final CompatClient client = serviceTalkClient(server.listenAddress(), ssl); testGrpcError(client, server, false, streaming); }
Example #30
Source File: ProtocolCompatibilityTest.java From servicetalk with Apache License 2.0 | 5 votes |
@Theory public void serviceTalkToServiceTalkErrorViaServiceFilter(@FromDataPoints("ssl") final boolean ssl, @FromDataPoints("streaming") final boolean streaming) throws Exception { final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE_IN_SERVICE_FILTER, ssl); final CompatClient client = serviceTalkClient(server.listenAddress(), ssl); testGrpcError(client, server, false, streaming); }