How do you assert that an exception was thrown in JUnit 4 tests?

How to use JUnit 4 to test some code to throw exceptions? Although I can certainly do such things: @Test public void testFooThrowsIndexOutOfBoundsException() { boolean thrown = false; try { foo.doStuff(); } catch (IndexOutOfBoundsException e) { thrown = true; } assertTrue(thrown); } I remember in this case, having a ...

Posted by ivki on Thu, 05 Dec 2019 07:17:29 -0800

Java non blocking NIO case (realize multi person chat function)

I. three cores of using Java NIO to complete network communication 1. Channel: responsible for connection java.nio.channels.Channel interface:              |--SelectableChannel                  |--SocketChannel                  |--ServerSocketChannel                  |--DatagramChannel                    |--Pipe.SinkChannel                  |-- ...

Posted by gergy008 on Tue, 03 Dec 2019 06:06:53 -0800

Deep understanding of lambda expression and functional programming functional interface source code analysis

package com.java.design.java8; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.util.Arrays; import java.util.Compar ...

Posted by jordz on Tue, 03 Dec 2019 01:56:08 -0800

Simulate HTTP request to call controller

Please refer to my brief book: Simulate HTTP request to call controller Written in front MockMvc realizes the simulation of Http request, and can directly use the form of network to convert to Controller call, which makes the test faster and does not depend on the network environment. It also provides a set of verification tools. The single tes ...

Posted by Stoned Gecko on Tue, 03 Dec 2019 01:17:34 -0800

Simple use of VirtualAPK

Steps to introduce VirtualApk: I. Introduction of virtual APK to host application 1. Add dependency in the build.gradle file of the project: dependencies { classpath 'com.didi.virtualapk:gradle:0.9.8.6' } The complete gradle file is as follows: // Top-level build file where you can add configuration options common to all sub-projects/module ...

Posted by darksniperx on Sun, 01 Dec 2019 14:38:17 -0800

Spring boot uses redis through redisTemplate without manual serialization

                     For some operations of redisTemplate, please refer to the following two articles http://blog.csdn.net/whatlookingfor/article/details/51863286 http://www.jianshu.com/p/7bf5dc61ca06 Import redis dependency <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spr ...

Posted by departedmind on Mon, 25 Nov 2019 12:58:04 -0800

Why is it not necessary to write version number < version > when writing dependencies < dependencies > in maven configuration of some spring projects

Why do you not need to write version number when writing dependency in maven configuration of some spring projects I. The first situation: <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId&gt ...

Posted by sherri on Sun, 24 Nov 2019 14:24:27 -0800

Groovy Unit Test Framework spock Data Driven Demo

spock is an all-round unit testing framework. The last article shared the use of the basic features of the spock framework, and on that basis, I made some attempts based on Groovy encapsulation, data-driven, and some advanced Groovy syntax I wrote.There's still a bit of a problem, I don't know if it's because I'm a Java and Groovy hybrid proj ...

Posted by MLJJ on Sun, 17 Nov 2019 00:01:42 -0800

shiro four encryption realm login and logout

shiro encryption operation Hash algorithm is generally used to generate summary information of data. It is an irreversible algorithm, which is generally suitable for storing data such as passwords, and common hash legal persons such as MD5 and SHA. In general, it is better to provide a salt for hash algorithm, such as encrypte ...

Posted by isuckat_php on Sat, 16 Nov 2019 14:12:58 -0800

Activity5 workflow (6)

Three ways to assign personal tasks User task is the task of user operation. Personal task is one of user tasks. This blog will briefly introduce three ways to assign personal tasks. I. flow chart ​ Figure 1 flow chart of user task allocation 2. Method 1: directly appoint the handler 1. Configure task nodes in the flowch ...

Posted by mpb001 on Fri, 15 Nov 2019 12:11:24 -0800