@Test public void getText_withLayoutId() throws Exception { // This isn't _really_ supported by the platform (gives a lint warning that getText() expects a String resource type // but the actual platform behaviour is to return a string that equals "res/layout/layout_file.xml" so the current // Robolectric behaviour deviates from the platform as we append the full file path from the current working directory. assertThat(resources.getText(R.layout.different_screen_sizes, "value").toString()) .containsMatch("layout" + File.separator + "different_screen_sizes.xml$"); }
@Test public void generateTargetingForNativeLibraries_abiBaseNamesDisallowed() throws Exception { String directoryName = "lib/ARM64-v8a"; ValidationException exception = assertThrows( ValidationException.class, () -> generator.generateTargetingForNativeLibraries(ImmutableList.of(directoryName))); assertThat(exception) .hasMessageThat() .containsMatch( "Expecting ABI name in file or directory 'lib/ARM64-v8a', but found 'ARM64-v8a' " + "which is not recognized. Did you mean 'arm64-v8a'?"); }
@Test public void generateTargetingForApexImages_abiBaseNamesDisallowed() throws Exception { ValidationException exception = assertThrows( ValidationException.class, () -> generator.generateTargetingForApexImages( ImmutableList.of(ZipPath.create("x86.ARM64-v8a.img")))); assertThat(exception) .hasMessageThat() .containsMatch( "Expecting ABI name in file or directory 'x86.ARM64-v8a.img', but found 'ARM64-v8a' " + "which is not recognized. Did you mean 'arm64-v8a'?"); }
@Test public void helloInfoTest() { String result = HelloAppEngine.getInfo(); assertThat(result) .named("HelloInfo.getInfo") .containsMatch("^Version:\\s+.+OS:\\s+.+User:\\s"); } }
@Test public void helloInfoTest() { String result = HelloAppEngine.getInfo(); assertThat(result) .named("HelloInfo.getInfo") .containsMatch("^Version:\\s+.+OS:\\s+.+User:\\s"); } }
/** * Run the gradient field example class. */ @Test public void gradientFieldExample() { try { GradientFieldExample.run(true); } catch (final RuntimeException e) { // find the root cause of the exception Throwable cur = e; while (cur.getCause() != null) { cur = cur.getCause(); } // verify that the exception was caused by the early termination of the // simulation assertTrue(cur.toString(), cur instanceof IllegalStateException); assertThat(cur.getMessage()).containsMatch( "The simulation did not result in a valid result"); } }
/** * A builder that has no declared dependencies can not request any. */ @Test public void testAskWithoutAnyDepsBuilder() { final Simulator.Builder b = Simulator.builder(); boolean fail = false; try { b.addModel(new AskWithoutAnyDepsBuilder()); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).containsMatch( "did not declare any dependencies"); fail = true; } assertThat(fail).isTrue(); }
@Test public void testMissingSymbolOrExtern() { assertThatProgram( "goog.provide('foo.x');", "/** @param {some.Unknown} y */", "foo.x = function(y) {};") .diagnosticStream() .containsMatch("ERROR.*missing some types"); }
@Test public void testDuplicateSymbol() { // Useful assertThatProgram("/** @type {number} */ var x = 1;", "/** @type {number} */ var x = 2;") .diagnosticStream() .containsMatch("ERROR.*Variable x declared more than once"); }
@Test public void testReportsWarningsInTests() { assertThatProgram("/** @see */", "var noSee;") .diagnosticStream() .containsMatch("WARNING.*@see tag missing description"); } }
/** * Tests that a not handled event results in a {@link IllegalStateException}. */ @Test public void testEventNotHandled() { final ScenarioController.Builder b = ScenarioController.builder(scenario) .withNumberOfTicks(3); boolean fail = false; try { b.build(dependencyProvider); } catch (final IllegalStateException e) { assertThat(e.getMessage()).containsMatch("No handler found for event"); fail = true; } assertThat(fail).isTrue(); }
/** * Tests that handling an interface is rejected. */ @Test public void testHandleInterface() { boolean fail = false; try { ScenarioController.builder(scenario) .withEventHandler(TimedEvent.class, new NopHandler<>()).toString(); } catch (final IllegalArgumentException e) { fail = true; assertThat(e.getMessage()).containsMatch("Must handle a concrete class"); } assertThat(fail).isTrue(); }
/** * Tests that asking a undeclared dependency results in a failure. */ @Test public void testAskWrongTypeBuilder() { final Simulator.Builder b = Simulator.builder() .addModel(new AskWrongTypeBuilder()) .addModel(new A()) .addModel(new B()); boolean fail = false; try { b.build(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).containsMatch("is not a type that"); assertThat(e.getMessage()).containsMatch("declared as a dependency"); fail = true; } assertThat(fail).isTrue(); }
/** * Tests that not using a dependency is detected. */ @Test public void testNopBuilder() { final Simulator.Builder b = Simulator.builder() .addModel(new NopBuilder()) .addModel(new A()) .addModel(new B()); boolean fail = false; try { b.build(); } catch (final IllegalStateException e) { assertThat(e.getMessage()) .containsMatch("dependencies MUST be requested"); fail = true; } assertThat(fail).isTrue(); }
/** * Tests that requesting two instances of a type results in a failure. */ @Test public void testAskTwiceBuilder() { final Simulator.Builder b = Simulator.builder() .addModel(new AskTwiceBuilder()) .addModel(new A()) .addModel(new B()); boolean fail = false; try { b.build(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).containsMatch("is already requested"); fail = true; } assertThat(fail).isTrue(); }