Skip to content

Instantly share code, notes, and snippets.

View mooingcat's full-sized avatar

Katie Moulang mooingcat

  • BeZero Carbon
View GitHub Profile
@mooingcat
mooingcat / springthings.md
Last active March 16, 2017 15:35
Snippets of useful Spring things

Testing

Best bits of https://spring.io/guides/gs/testing-web/:

Dependency

testCompile("org.springframework.boot:spring-boot-starter-test")

MockMvc

@AutoConfigureMockMvc on your test class, injects a MockMvc instance when you Autowired one. (You'll probably need @RunWith(SpringRunner.class) and @SpringBootTest too.)

git cherry -v master feature
Shadows.shadowOf(RuntimeEnvironment.application.resources.configuration).setLocale(Locale("fr"));
@mooingcat
mooingcat / gist:26de8f5ed5a741a48e0c9e37382d90be
Created May 31, 2016 09:58
Tests erroring in Android studio
If your tests run in the command line but error in Android Studio, you
may need to add `-noverify` to the VM options in the JUnit run
configuration.
Error may look something like
java.lang.VerifyError: Expecting a stackmap frame at branch target
@mooingcat
mooingcat / 1_test.java
Last active March 7, 2019 01:18
Testing with Robolectric what the intent is when clicking a notification in android
@Test
public void clickingOnTheTextOpensANotificationWhichOpensTheResultActivity() {
DeckardActivity activity = Robolectric.setupActivity(DeckardActivity.class);
View text = activity.findViewById(R.id.text);
text.performClick();
NotificationManager notificationService = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
ShadowNotificationManager shadowNotificationManager = shadowOf(notificationService);
assertThat(shadowNotificationManager.size(), equalTo(1));