Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)

Preface

It's easier, but a little sloppy. As the title suggests, we use PowerMockito.

code

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.junit.Assert.assertTrue;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;

@RunWith(PowerMockRunner.class)
public class MyTest {

    @Test
    public void test() {
        final Integer a = mock(Integer.class);
        when(a.intValue()).thenReturn(1, 2, 3);
        assertTrue(a == 1 && a == 2 && a == 3);
    }
}

A little commentary

As you know, PowerMockito is a library that allows you to create mockups of the final class and make them various. Auto unboxing allows you to compare a ʻInteger object with a primitive ʻint by ==. Also, since ʻInteger # intValue` is called in auto unboxing, the values to be returned at this time were specified in order with PowerMockito.

Recommended Posts

Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (black magic edition)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Javassist second decoction)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (Royal road edition that is neither magic nor anything)
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (gray magic that is not so much as black magic)
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I want to ForEach an array with a Lambda expression in Java
Output true with if (a == 1 && a == 2 && a == 3) in Java (Invisible Identifier)
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
I want to create a Parquet file even in Ruby
[Java] I want to test standard input & standard output with JUnit
[Java] I want to perform distinct with the key in the object
I did Java to make (a == 1 && a == 2 && a == 3) always true
I want to select multiple items with a custom layout in Dialog
I want to use java8 forEach with index
I want to create a dark web SNS with Jakarta EE 8 with Java 11
rsync4j --I want to touch rsync in Java.
I want to display a PDF in Chinese (Korean) with thin reports
I tried to output multiplication table in Java
I want to be eventually even in kotlin
I tried to break a block with java (1)
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I want to use a little icon in Rails
I tried to create a Clova skill in Java
I want to monitor a specific file with WatchService
I tried to make a login function in Java
I want to define a function in Rails Console
I want to transition screens with kotlin and java!
I want to click a GoogleMap pin in RSpec
I want to get along with Map [Java beginner]
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
I want to return an object in CSV format with multi-line header & filter in Java
I made a function to register images with API in Spring Framework. Part 1 (API edition)
I tried to create a java8 development environment with Chocolatey
I tried to modernize a Java EE application with OpenShift.
[Java] I want to convert a byte array to a hexadecimal number
I want to find a relative path in a situation using Path
[Beginner] I made a program to sell cakes in Java
I just wanted to make a Reactive Property in Java
I tried to convert a string to a LocalDate type in Java
I tried to make a client of RESAS-API in Java
I want to implement various functions with kotlin and java!
I want to simplify the conditional if-else statement in Java
Even if I want to convert the contents of a data object to JSON in Java, there is a circular reference ...
I created a PDF in Java.
I want to write a loop that references an index with Java 8's Stream API
[CQ Engine] I want to handle collections like Stream or .Net LINQ even in Java 7.
I tried to interact with Java
Log output to file in Java
I want to Flash Attribute in Spring even if I set a reverse proxy! (do not do)
I want to return a type different from the input element with Java8 StreamAPI reduce ()
I made a function to register images with API in Spring Framework. Part 2 (Client Edition)
A story that I struggled to challenge a competition professional with Java
I want to make a button with a line break with link_to [Note]
I want to add a browsing function with ruby on rails
I can't create a Java class with a specific name in IntelliJ
I want to return to the previous screen with kotlin and java!
[Ruby] I want to put an array in a variable. I want to convert to an array
I want to extract between character strings with a regular expression