Merge branch 'master' into BAEL-1689
This commit is contained in:
commit
9fd6025127
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class CayenneAdvancedOperationIntegrationTest {
|
||||
public class CayenneAdvancedOperationLiveTest {
|
||||
private static ObjectContext context = null;
|
||||
|
||||
@BeforeClass
|
|
@ -16,7 +16,7 @@ import static junit.framework.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNull;
|
||||
|
||||
|
||||
public class CayenneOperationIntegrationTest {
|
||||
public class CayenneOperationLiveTest {
|
||||
private static ObjectContext context = null;
|
||||
|
||||
@BeforeClass
|
|
@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class AzureApplicationTests {
|
||||
public class AzureApplicationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
|
@ -195,6 +195,16 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<compilerArgument>-parameters</compilerArgument>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.baeldung.reflect;
|
||||
|
||||
public class Person {
|
||||
|
||||
private String fullName;
|
||||
|
||||
public Person(String fullName) {
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
public void setFullName(String fullName) {
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.baeldung.reflect;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class MethodParamNameUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenGetConstructorParams_thenOk()
|
||||
throws NoSuchMethodException, SecurityException {
|
||||
List<Parameter> parameters
|
||||
= Arrays.asList(Person.class.getConstructor(String.class).getParameters());
|
||||
Optional<Parameter> parameter
|
||||
= parameters.stream().filter(Parameter::isNamePresent).findFirst();
|
||||
assertThat(parameter.get().getName()).isEqualTo("fullName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetMethodParams_thenOk()
|
||||
throws NoSuchMethodException, SecurityException {
|
||||
List<Parameter> parameters
|
||||
= Arrays.asList(
|
||||
Person.class.getMethod("setFullName", String.class).getParameters());
|
||||
Optional<Parameter> parameter
|
||||
= parameters.stream().filter(Parameter::isNamePresent).findFirst();
|
||||
assertThat(parameter.get().getName()).isEqualTo("fullName");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,199 @@
|
|||
package com.baeldung.java9.modules;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.collection.IsEmptyCollection.empty;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.module.ModuleDescriptor;
|
||||
import java.lang.module.ModuleDescriptor.*;
|
||||
import java.sql.Date;
|
||||
import java.sql.Driver;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ModuleAPIUnitTest {
|
||||
|
||||
public static final String JAVA_BASE_MODULE_NAME = "java.base";
|
||||
|
||||
private Module javaBaseModule;
|
||||
private Module javaSqlModule;
|
||||
private Module module;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Class<HashMap> hashMapClass = HashMap.class;
|
||||
javaBaseModule = hashMapClass.getModule();
|
||||
|
||||
Class<Date> dateClass = Date.class;
|
||||
javaSqlModule = dateClass.getModule();
|
||||
|
||||
Class<Person> personClass = Person.class;
|
||||
module = personClass.getModule();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckingIfNamed_thenModuleIsNamed() {
|
||||
assertThat(javaBaseModule.isNamed(), is(true));
|
||||
assertThat(javaBaseModule.getName(), is(JAVA_BASE_MODULE_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCheckingIfNamed_thenModuleIsUnnamed() {
|
||||
assertThat(module.isNamed(), is(false));
|
||||
assertThat(module.getName(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenExtractingPackagesContainedInAModule_thenModuleContainsOnlyFewOfThem() {
|
||||
assertTrue(javaBaseModule.getPackages().contains("java.lang.annotation"));
|
||||
assertFalse(javaBaseModule.getPackages().contains("java.sql"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrievingClassLoader_thenClassLoaderIsReturned() {
|
||||
assertThat(
|
||||
module.getClassLoader().getClass().getName(),
|
||||
is("jdk.internal.loader.ClassLoaders$AppClassLoader")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGettingAnnotationsPresentOnAModule_thenNoAnnotationsArePresent() {
|
||||
assertThat(javaBaseModule.getAnnotations().length, is(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGettingLayerOfAModule_thenModuleLayerInformationAreAvailable() {
|
||||
ModuleLayer javaBaseModuleLayer = javaBaseModule.getLayer();
|
||||
|
||||
assertTrue(javaBaseModuleLayer.configuration().findModule(JAVA_BASE_MODULE_NAME).isPresent());
|
||||
assertThat(javaBaseModuleLayer.configuration().modules().size(), is(78));
|
||||
assertTrue(javaBaseModuleLayer.parents().get(0).configuration().parents().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRetrievingModuleDescriptor_thenTypeOfModuleIsInferred() {
|
||||
ModuleDescriptor javaBaseModuleDescriptor = javaBaseModule.getDescriptor();
|
||||
ModuleDescriptor javaSqlModuleDescriptor = javaSqlModule.getDescriptor();
|
||||
|
||||
assertFalse(javaBaseModuleDescriptor.isAutomatic());
|
||||
assertFalse(javaBaseModuleDescriptor.isOpen());
|
||||
assertFalse(javaSqlModuleDescriptor.isAutomatic());
|
||||
assertFalse(javaSqlModuleDescriptor.isOpen());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModuleName_whenBuildingModuleDescriptor_thenBuilt() {
|
||||
Builder moduleBuilder = ModuleDescriptor.newModule("baeldung.base");
|
||||
|
||||
ModuleDescriptor moduleDescriptor = moduleBuilder.build();
|
||||
|
||||
assertThat(moduleDescriptor.name(), is("baeldung.base"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorRequires_thenRequiresAreReturned() {
|
||||
Set<Requires> javaBaseRequires = javaBaseModule.getDescriptor().requires();
|
||||
Set<Requires> javaSqlRequires = javaSqlModule.getDescriptor().requires();
|
||||
|
||||
Set<String> javaSqlRequiresNames = javaSqlRequires.stream()
|
||||
.map(Requires::name)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
assertThat(javaBaseRequires, empty());
|
||||
assertThat(javaSqlRequires.size(), is(3));
|
||||
assertThat(javaSqlRequiresNames, containsInAnyOrder("java.base", "java.xml", "java.logging"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorProvides_thenProvidesAreReturned() {
|
||||
Set<Provides> javaBaseProvides = javaBaseModule.getDescriptor().provides();
|
||||
Set<Provides> javaSqlProvides = javaSqlModule.getDescriptor().provides();
|
||||
|
||||
Set<String> javaBaseProvidesService = javaBaseProvides.stream()
|
||||
.map(Provides::service)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
assertThat(javaBaseProvidesService, contains("java.nio.file.spi.FileSystemProvider"));
|
||||
assertThat(javaSqlProvides, empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorExports_thenExportsAreReturned() {
|
||||
Set<Exports> javaBaseExports = javaBaseModule.getDescriptor().exports();
|
||||
Set<Exports> javaSqlExports = javaSqlModule.getDescriptor().exports();
|
||||
|
||||
Set<String> javaSqlExportsSource = javaSqlExports.stream()
|
||||
.map(Exports::source)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
assertThat(javaBaseExports.size(), is(108));
|
||||
assertThat(javaSqlExports.size(), is(3));
|
||||
assertThat(javaSqlExportsSource, containsInAnyOrder("java.sql", "javax.transaction.xa", "javax.sql"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorUses_thenUsesAreReturned() {
|
||||
Set<String> javaBaseUses = javaBaseModule.getDescriptor().uses();
|
||||
Set<String> javaSqlUses = javaSqlModule.getDescriptor().uses();
|
||||
|
||||
assertThat(javaBaseUses.size(), is(34));
|
||||
assertThat(javaSqlUses, contains("java.sql.Driver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenModules_whenAccessingModuleDescriptorOpen_thenOpenAreReturned() {
|
||||
Set<Opens> javaBaseUses = javaBaseModule.getDescriptor().opens();
|
||||
Set<Opens> javaSqlUses = javaSqlModule.getDescriptor().opens();
|
||||
|
||||
assertThat(javaBaseUses, empty());
|
||||
assertThat(javaSqlUses, empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingReadsToAModule_thenModuleCanReadNewModule() {
|
||||
Module updatedModule = module.addReads(javaSqlModule);
|
||||
|
||||
assertTrue(updatedModule.canRead(javaSqlModule));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenExportingPackage_thenPackageIsExported() {
|
||||
Module updatedModule = module.addExports("com.baeldung.java9.modules", javaSqlModule);
|
||||
|
||||
assertTrue(updatedModule.isExported("com.baeldung.java9.modules"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenOpeningAModulePackage_thenPackagedIsOpened() {
|
||||
Module updatedModule = module.addOpens("com.baeldung.java9.modules", javaSqlModule);
|
||||
|
||||
assertTrue(updatedModule.isOpen("com.baeldung.java9.modules", javaSqlModule));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingUsesToModule_thenUsesIsAdded() {
|
||||
Module updatedModule = module.addUses(Driver.class);
|
||||
|
||||
assertTrue(updatedModule.canUse(Driver.class));
|
||||
}
|
||||
|
||||
private class Person {
|
||||
private String name;
|
||||
|
||||
public Person(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -77,6 +77,6 @@ public class FilesManualTest {
|
|||
bw.newLine();
|
||||
bw.close();
|
||||
|
||||
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\n");
|
||||
assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
|
||||
}
|
||||
}
|
|
@ -106,7 +106,7 @@ public class JavaReadFromFileUnitTest {
|
|||
|
||||
@Test
|
||||
public void whenReadUTFEncodedFile_thenCorrect() throws IOException {
|
||||
final String expected_value = "é<EFBFBD>’空";
|
||||
final String expected_value = "青空";
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/test/resources/test_read7.in"), "UTF-8"));
|
||||
final String currentLine = reader.readLine();
|
||||
reader.close();
|
||||
|
|
|
@ -198,6 +198,11 @@
|
|||
<artifactId>mail</artifactId>
|
||||
<version>${javax.mail.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.5.0-b01</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package com.baeldung.array;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class JaggedArray {
|
||||
|
||||
int[][] shortHandFormInitialization() {
|
||||
int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
|
||||
return jaggedArr;
|
||||
}
|
||||
|
||||
int[][] declarationAndThenInitialization() {
|
||||
int[][] jaggedArr = new int[3][];
|
||||
jaggedArr[0] = new int[] { 1, 2 };
|
||||
jaggedArr[1] = new int[] { 3, 4, 5 };
|
||||
jaggedArr[2] = new int[] { 6, 7, 8, 9 };
|
||||
return jaggedArr;
|
||||
}
|
||||
|
||||
int[][] declarationAndThenInitializationUsingUserInputs() {
|
||||
int[][] jaggedArr = new int[3][];
|
||||
jaggedArr[0] = new int[2];
|
||||
jaggedArr[1] = new int[3];
|
||||
jaggedArr[2] = new int[4];
|
||||
initializeElements(jaggedArr);
|
||||
return jaggedArr;
|
||||
}
|
||||
|
||||
void initializeElements(int[][] jaggedArr) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
for (int outer = 0; outer < jaggedArr.length; outer++) {
|
||||
for (int inner = 0; inner < jaggedArr[outer].length; inner++) {
|
||||
jaggedArr[outer][inner] = sc.nextInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void printElements(int[][] jaggedArr) {
|
||||
for (int index = 0; index < jaggedArr.length; index++) {
|
||||
System.out.println(Arrays.toString(jaggedArr[index]));
|
||||
}
|
||||
}
|
||||
|
||||
int[] getElementAtGivenIndex(int[][] jaggedArr, int index) {
|
||||
return jaggedArr[index];
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.baeldung.array;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class JaggedArrayUnitTest {
|
||||
|
||||
private JaggedArray obj = new JaggedArray();
|
||||
|
||||
@Test
|
||||
public void whenInitializedUsingShortHandForm_thenCorrect() {
|
||||
assertArrayEquals(new int[][] { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }, obj.shortHandFormInitialization());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInitializedWithDeclarationAndThenInitalization_thenCorrect() {
|
||||
assertArrayEquals(new int[][] { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }, obj.declarationAndThenInitialization());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInitializedWithDeclarationAndThenInitalizationUsingUserInputs_thenCorrect() {
|
||||
InputStream is = new ByteArrayInputStream("1 2 3 4 5 6 7 8 9".getBytes());
|
||||
System.setIn(is);
|
||||
assertArrayEquals(new int[][] { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } }, obj.declarationAndThenInitializationUsingUserInputs());
|
||||
System.setIn(System.in);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenJaggedArrayAndAnIndex_thenReturnArrayAtGivenIndex() {
|
||||
int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
|
||||
assertArrayEquals(new int[] { 1, 2 }, obj.getElementAtGivenIndex(jaggedArr, 0));
|
||||
assertArrayEquals(new int[] { 3, 4, 5 }, obj.getElementAtGivenIndex(jaggedArr, 1));
|
||||
assertArrayEquals(new int[] { 6, 7, 8, 9 }, obj.getElementAtGivenIndex(jaggedArr, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenJaggedArray_whenUsingArraysAPI_thenVerifyPrintedElements() {
|
||||
int[][] jaggedArr = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } };
|
||||
ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(outContent));
|
||||
obj.printElements(jaggedArr);
|
||||
assertEquals("[1, 2]\n[3, 4, 5]\n[6, 7, 8, 9]\n", outContent.toString());
|
||||
System.setOut(System.out);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.baeldung.enums
|
||||
|
||||
enum class CardType(val color: String) : ICardLimit {
|
||||
SILVER("gray") {
|
||||
override fun getCreditLimit(): Int {
|
||||
return 100000
|
||||
}
|
||||
|
||||
override fun calculateCashbackPercent(): Float {
|
||||
return 0.25f
|
||||
}
|
||||
},
|
||||
GOLD("yellow") {
|
||||
override fun getCreditLimit(): Int {
|
||||
return 200000
|
||||
}
|
||||
|
||||
override fun calculateCashbackPercent(): Float {
|
||||
return 0.5f
|
||||
}
|
||||
},
|
||||
PLATINUM("black") {
|
||||
override fun getCreditLimit(): Int {
|
||||
return 300000
|
||||
}
|
||||
|
||||
override fun calculateCashbackPercent(): Float {
|
||||
return 0.75f
|
||||
}
|
||||
};
|
||||
|
||||
abstract fun calculateCashbackPercent(): Float
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.enums
|
||||
|
||||
class CardTypeHelper {
|
||||
fun getCardTypeByColor(color: String): CardType? {
|
||||
for (cardType in CardType.values()) {
|
||||
if (cardType.color.equals(color)) {
|
||||
return cardType;
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun getCardTypeByName(name: String): CardType {
|
||||
return CardType.valueOf(name.toUpperCase())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.baeldung.enums
|
||||
|
||||
interface ICardLimit {
|
||||
fun getCreditLimit(): Int
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.baeldung.enums
|
||||
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
internal class CardTypeHelperUnitTest {
|
||||
|
||||
@Test
|
||||
fun whenGetCardTypeByColor_thenSilverCardType() {
|
||||
val cardTypeHelper = CardTypeHelper()
|
||||
Assertions.assertEquals(CardType.SILVER, cardTypeHelper.getCardTypeByColor("gray"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGetCardTypeByColor_thenGoldCardType() {
|
||||
val cardTypeHelper = CardTypeHelper()
|
||||
Assertions.assertEquals(CardType.GOLD, cardTypeHelper.getCardTypeByColor("yellow"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGetCardTypeByColor_thenPlatinumCardType() {
|
||||
val cardTypeHelper = CardTypeHelper()
|
||||
Assertions.assertEquals(CardType.PLATINUM, cardTypeHelper.getCardTypeByColor("black"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGetCardTypeByName_thenSilverCardType() {
|
||||
val cardTypeHelper = CardTypeHelper()
|
||||
Assertions.assertEquals(CardType.SILVER, cardTypeHelper.getCardTypeByName("silver"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGetCardTypeByName_thenGoldCardType() {
|
||||
val cardTypeHelper = CardTypeHelper()
|
||||
Assertions.assertEquals(CardType.GOLD, cardTypeHelper.getCardTypeByName("gold"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGetCardTypeByName_thenPlatinumCardType() {
|
||||
val cardTypeHelper = CardTypeHelper()
|
||||
Assertions.assertEquals(CardType.PLATINUM, cardTypeHelper.getCardTypeByName("platinum"))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.baeldung.enums
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
internal class CardTypeUnitTest {
|
||||
|
||||
@Test
|
||||
fun givenSilverCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
|
||||
assertEquals(0.25f, CardType.SILVER.calculateCashbackPercent())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenGoldCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
|
||||
assertEquals(0.5f, CardType.GOLD.calculateCashbackPercent())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenPlatinumCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
|
||||
assertEquals(0.75f, CardType.PLATINUM.calculateCashbackPercent())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenSilverCardType_whenGetCreditLimit_thenReturnCreditLimit() {
|
||||
assertEquals(100000, CardType.SILVER.getCreditLimit())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenGoldCardType_whenGetCreditLimit_thenReturnCreditLimit() {
|
||||
assertEquals(200000, CardType.GOLD.getCreditLimit())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenPlatinumCardType_whenGetCreditLimit_thenReturnCreditLimit() {
|
||||
assertEquals(300000, CardType.PLATINUM.getCreditLimit())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenSilverCardType_whenCheckColor_thenReturnColor() {
|
||||
assertEquals("gray", CardType.SILVER.color)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenGoldCardType_whenCheckColor_thenReturnColor() {
|
||||
assertEquals("yellow", CardType.GOLD.color)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenPlatinumCardType_whenCheckColor_thenReturnColor() {
|
||||
assertEquals("black", CardType.PLATINUM.color)
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -14,18 +14,17 @@ public class UnitTestNamingConventionRule extends AbstractJavaRule {
|
|||
"ManualTest",
|
||||
"JdbcTest",
|
||||
"LiveTest",
|
||||
"UnitTest");
|
||||
"UnitTest",
|
||||
"jmhTest");
|
||||
|
||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
String className = node.getImage();
|
||||
Objects.requireNonNull(className);
|
||||
|
||||
if (className.endsWith("Test") || className.endsWith("Tests")) {
|
||||
if (allowedEndings.stream()
|
||||
.noneMatch(className::endsWith)) {
|
||||
if (className.endsWith("Tests")
|
||||
|| (className.endsWith("Test") && allowedEndings.stream().noneMatch(className::endsWith))) {
|
||||
addViolation(data, node);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
|||
}, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
|
||||
@AutoConfigureMockMvc
|
||||
@ActiveProfiles("dev")
|
||||
public class FlipControllerTest {
|
||||
public class FlipControllerIntegrationTest {
|
||||
|
||||
@Autowired private MockMvc mvc;
|
||||
|
|
@ -698,6 +698,17 @@
|
|||
<artifactId>jctools-core</artifactId>
|
||||
<version>${jctools.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>${common-math3-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.knowm.xchart</groupId>
|
||||
<artifactId>xchart</artifactId>
|
||||
<version>${xchart-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
|
@ -910,6 +921,8 @@
|
|||
<jets3t-version>0.9.4.0006L</jets3t-version>
|
||||
<jctools.version>2.1.2</jctools.version>
|
||||
<typesafe-akka.version>2.5.11</typesafe-akka.version>
|
||||
<common-math3-version>3.6.1</common-math3-version>
|
||||
<xchart-version>3.5.2</xchart-version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,95 @@
|
|||
package com.baeldung.commons.math3;
|
||||
|
||||
import org.apache.commons.math3.stat.Frequency;
|
||||
import org.knowm.xchart.CategoryChart;
|
||||
import org.knowm.xchart.CategoryChartBuilder;
|
||||
import org.knowm.xchart.SwingWrapper;
|
||||
import org.knowm.xchart.style.Styler;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Histogram {
|
||||
|
||||
private Map distributionMap;
|
||||
private int classWidth;
|
||||
|
||||
public Histogram() {
|
||||
|
||||
distributionMap = new TreeMap();
|
||||
classWidth = 10;
|
||||
Map distributionMap = processRawData();
|
||||
List yData = new ArrayList();
|
||||
yData.addAll(distributionMap.values());
|
||||
List xData = Arrays.asList(distributionMap.keySet().toArray());
|
||||
|
||||
CategoryChart chart = buildChart(xData, yData);
|
||||
new SwingWrapper<>(chart).displayChart();
|
||||
|
||||
}
|
||||
|
||||
private CategoryChart buildChart(List xData, List yData) {
|
||||
|
||||
// Create Chart
|
||||
CategoryChart chart = new CategoryChartBuilder().width(800).height(600)
|
||||
.title("Age Distribution")
|
||||
.xAxisTitle("Age Group")
|
||||
.yAxisTitle("Frequency")
|
||||
.build();
|
||||
|
||||
chart.getStyler().setLegendPosition(Styler.LegendPosition.InsideNW);
|
||||
chart.getStyler().setAvailableSpaceFill(0.99);
|
||||
chart.getStyler().setOverlapped(true);
|
||||
|
||||
chart.addSeries("age group", xData, yData);
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
private Map processRawData() {
|
||||
|
||||
List<Integer> datasetList = Arrays.asList(36, 25, 38, 46, 55, 68, 72, 55, 36, 38, 67, 45, 22, 48, 91, 46, 52, 61, 58, 55);
|
||||
Frequency frequency = new Frequency();
|
||||
datasetList.forEach(d -> frequency.addValue(Double.parseDouble(d.toString())));
|
||||
|
||||
List processed = new ArrayList();
|
||||
datasetList.forEach(d -> {
|
||||
double observation = Double.parseDouble(d.toString());
|
||||
|
||||
if(processed.contains(observation))
|
||||
return;
|
||||
|
||||
long observationFrequency = frequency.getCount(observation);
|
||||
int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth;
|
||||
int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0;
|
||||
String bin = lowerBoundary + "-" + upperBoundary;
|
||||
|
||||
updateDistributionMap(lowerBoundary, bin, observationFrequency);
|
||||
|
||||
processed.add(observation);
|
||||
|
||||
});
|
||||
|
||||
return distributionMap;
|
||||
}
|
||||
|
||||
private void updateDistributionMap(int lowerBoundary, String bin, long observationFrequency) {
|
||||
|
||||
int prevLowerBoundary = (lowerBoundary > classWidth) ? lowerBoundary - classWidth : 0;
|
||||
String prevBin = prevLowerBoundary + "-" + lowerBoundary;
|
||||
if(!distributionMap.containsKey(prevBin))
|
||||
distributionMap.put(prevBin, 0);
|
||||
|
||||
if(!distributionMap.containsKey(bin)) {
|
||||
distributionMap.put(bin, observationFrequency);
|
||||
}
|
||||
else {
|
||||
long oldFrequency = Long.parseLong(distributionMap.get(bin).toString());
|
||||
distributionMap.replace(bin, oldFrequency + observationFrequency);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Histogram();
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ import java.util.Map;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TodoMustacheServiceTest {
|
||||
public class TodoMustacheServiceUnitTest {
|
||||
|
||||
private String executeTemplate(Mustache m, Map<String, Object> context) throws IOException {
|
||||
StringWriter writer = new StringWriter();
|
|
@ -15,7 +15,7 @@ import org.junit.Test;
|
|||
* @author Donato Rimenti
|
||||
*
|
||||
*/
|
||||
public class SingletonSynchronizationUnitTest {
|
||||
public class SingletonSynchronizationIntegrationTest {
|
||||
|
||||
/**
|
||||
* Size of the thread pools used.
|
||||
|
@ -33,7 +33,7 @@ public class SingletonSynchronizationUnitTest {
|
|||
@Test
|
||||
public void givenDraconianSingleton_whenMultithreadInstancesEquals_thenTrue() {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
|
||||
Set<DraconianSingleton> resultSet = Collections.synchronizedSet(new HashSet<DraconianSingleton>());
|
||||
Set<DraconianSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
// Submits the instantiation tasks.
|
||||
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {
|
||||
|
@ -51,7 +51,7 @@ public class SingletonSynchronizationUnitTest {
|
|||
@Test
|
||||
public void givenDclSingleton_whenMultithreadInstancesEquals_thenTrue() {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
|
||||
Set<DclSingleton> resultSet = Collections.synchronizedSet(new HashSet<DclSingleton>());
|
||||
Set<DclSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
// Submits the instantiation tasks.
|
||||
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {
|
||||
|
@ -69,7 +69,7 @@ public class SingletonSynchronizationUnitTest {
|
|||
@Test
|
||||
public void givenEarlyInitSingleton_whenMultithreadInstancesEquals_thenTrue() {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
|
||||
Set<EarlyInitSingleton> resultSet = Collections.synchronizedSet(new HashSet<EarlyInitSingleton>());
|
||||
Set<EarlyInitSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
// Submits the instantiation tasks.
|
||||
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {
|
||||
|
@ -87,7 +87,7 @@ public class SingletonSynchronizationUnitTest {
|
|||
@Test
|
||||
public void givenInitOnDemandSingleton_whenMultithreadInstancesEquals_thenTrue() {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
|
||||
Set<InitOnDemandSingleton> resultSet = Collections.synchronizedSet(new HashSet<InitOnDemandSingleton>());
|
||||
Set<InitOnDemandSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
// Submits the instantiation tasks.
|
||||
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {
|
||||
|
@ -105,7 +105,7 @@ public class SingletonSynchronizationUnitTest {
|
|||
@Test
|
||||
public void givenEnumSingleton_whenMultithreadInstancesEquals_thenTrue() {
|
||||
ExecutorService executor = Executors.newFixedThreadPool(POOL_SIZE);
|
||||
Set<EnumSingleton> resultSet = Collections.synchronizedSet(new HashSet<EnumSingleton>());
|
||||
Set<EnumSingleton> resultSet = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
// Submits the instantiation tasks.
|
||||
for (int i = 0; i < TASKS_TO_SUBMIT; i++) {
|
5
pom.xml
5
pom.xml
|
@ -374,8 +374,8 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<failurePriority>5</failurePriority> <!-- TODO change to 0 after fixing the project -->
|
||||
<aggregate>true</aggregate>
|
||||
<failurePriority>5</failurePriority>
|
||||
<aggregate>false</aggregate>
|
||||
<failOnViolation>true</failOnViolation>
|
||||
<verbose>true</verbose>
|
||||
<linkXRef>true</linkXRef>
|
||||
|
@ -534,5 +534,4 @@
|
|||
<commons-fileupload.version>1.3</commons-fileupload.version>
|
||||
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
|||
}, webEnvironment = SpringBootTest.WebEnvironment.MOCK)
|
||||
@AutoConfigureMockMvc
|
||||
@ActiveProfiles("dev")
|
||||
public class FlipControllerTest {
|
||||
public class FlipControllerIntegrationTest {
|
||||
|
||||
@Autowired private MockMvc mvc;
|
||||
|
|
@ -141,6 +141,12 @@
|
|||
<artifactId>rxjava</artifactId>
|
||||
<version>${rxjava-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
<version>${project-reactor-test}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -185,6 +191,7 @@
|
|||
<jsonb-api.version>1.0</jsonb-api.version>
|
||||
<geronimo-json_1.1_spec.version>1.0</geronimo-json_1.1_spec.version>
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
<project-reactor-test>3.1.6.RELEASE</project-reactor-test>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
@ -25,26 +26,44 @@ public class AccountCrudRepositoryIntegrationTest {
|
|||
public void givenValue_whenFindAllByValue_thenFindAccount() {
|
||||
repository.save(new Account(null, "Bill", 12.3)).block();
|
||||
Flux<Account> accountFlux = repository.findAllByValue(12.3);
|
||||
Account account = accountFlux.next().block();
|
||||
|
||||
StepVerifier.create(accountFlux)
|
||||
.assertNext(account -> {
|
||||
assertEquals("Bill", account.getOwner());
|
||||
assertEquals(Double.valueOf(12.3) , account.getValue());
|
||||
assertNotNull(account.getId());
|
||||
})
|
||||
.expectComplete()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenOwner_whenFindFirstByOwner_thenFindAccount() {
|
||||
repository.save(new Account(null, "Bill", 12.3)).block();
|
||||
Mono<Account> accountMono = repository.findFirstByOwner(Mono.just("Bill"));
|
||||
Account account = accountMono.block();
|
||||
|
||||
StepVerifier.create(accountMono)
|
||||
.assertNext(account -> {
|
||||
assertEquals("Bill", account.getOwner());
|
||||
assertEquals(Double.valueOf(12.3) , account.getValue());
|
||||
assertNotNull(account.getId());
|
||||
})
|
||||
.expectComplete()
|
||||
.verify();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAccount_whenSave_thenSaveAccount() {
|
||||
Mono<Account> accountMono = repository.save(new Account(null, "Bill", 12.3));
|
||||
assertNotNull(accountMono.block().getId());
|
||||
|
||||
StepVerifier
|
||||
.create(accountMono)
|
||||
.assertNext(account -> assertNotNull(account.getId()))
|
||||
.expectComplete()
|
||||
.verify();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@ package com.baeldung.reactive.repository;
|
|||
|
||||
import com.baeldung.reactive.Spring5ReactiveApplication;
|
||||
import com.baeldung.reactive.model.Account;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -13,10 +11,10 @@ import org.springframework.data.domain.ExampleMatcher;
|
|||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
|
@ -32,23 +30,38 @@ public class AccountMongoRepositoryIntegrationTest {
|
|||
ExampleMatcher matcher = ExampleMatcher.matching().withMatcher("owner", startsWith());
|
||||
Example<Account> example = Example.of(new Account(null, "jo", null), matcher);
|
||||
Flux<Account> accountFlux = repository.findAll(example);
|
||||
List<Account> accounts = accountFlux.collectList().block();
|
||||
|
||||
assertTrue(accounts.stream().anyMatch(x -> x.getOwner().equals("john")));
|
||||
StepVerifier
|
||||
.create(accountFlux)
|
||||
.assertNext(account -> assertEquals("john", account.getOwner()))
|
||||
.expectComplete()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAccount_whenSave_thenSave() {
|
||||
Mono<Account> accountMono = repository.save(new Account(null, "john", 12.3));
|
||||
assertNotNull(accountMono.block().getId());
|
||||
|
||||
StepVerifier
|
||||
.create(accountMono)
|
||||
.assertNext(account -> assertNotNull(account.getId()))
|
||||
.expectComplete()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenId_whenFindById_thenFindAccount() {
|
||||
Account inserted = repository.save(new Account(null, "john", 12.3)).block();
|
||||
Mono<Account> accountMono = repository.findById(inserted.getId());
|
||||
assertEquals("john", accountMono.block().getOwner());
|
||||
assertEquals(Double.valueOf(12.3), accountMono.block().getValue());
|
||||
assertNotNull(accountMono.block().getId());
|
||||
|
||||
StepVerifier
|
||||
.create(accountMono)
|
||||
.assertNext(account -> {
|
||||
assertEquals("john", account.getOwner());
|
||||
assertEquals(Double.valueOf(12.3), account.getValue());
|
||||
assertNotNull(account.getId());
|
||||
})
|
||||
.expectComplete()
|
||||
.verify();
|
||||
}
|
||||
}
|
|
@ -21,23 +21,38 @@ public class AccountRxJavaRepositoryIntegrationTest {
|
|||
AccountRxJavaRepository repository;
|
||||
|
||||
@Test
|
||||
public void givenValue_whenFindAllByValue_thenFindAccounts() {
|
||||
public void givenValue_whenFindAllByValue_thenFindAccounts() throws InterruptedException {
|
||||
repository.save(new Account(null, "bruno", 12.3)).blockingGet();
|
||||
Observable<Account> accountObservable = repository.findAllByValue(12.3);
|
||||
Account account = accountObservable.filter(x -> x.getOwner().equals("bruno")).blockingFirst();
|
||||
|
||||
accountObservable
|
||||
.test()
|
||||
.await()
|
||||
.assertComplete()
|
||||
.assertValueAt(0, account -> {
|
||||
assertEquals("bruno", account.getOwner());
|
||||
assertEquals(Double.valueOf(12.3), account.getValue());
|
||||
assertNotNull(account.getId());
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenOwner_whenFindFirstByOwner_thenFindAccount() {
|
||||
public void givenOwner_whenFindFirstByOwner_thenFindAccount() throws InterruptedException {
|
||||
repository.save(new Account(null, "bruno", 12.3)).blockingGet();
|
||||
Single<Account> accountSingle = repository.findFirstByOwner(Single.just("bruno"));
|
||||
Account account = accountSingle.blockingGet();
|
||||
|
||||
accountSingle
|
||||
.test()
|
||||
.await()
|
||||
.assertComplete()
|
||||
.assertValueAt(0, account -> {
|
||||
assertEquals("bruno", account.getOwner());
|
||||
assertEquals(Double.valueOf(12.3), account.getValue());
|
||||
assertNotNull(account.getId());
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
package com.baeldung.persistence;
|
||||
|
||||
import com.baeldung.web.Foo;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
import com.baeldung.web.Foo;
|
||||
|
||||
public interface FooRepository extends JpaRepository<Foo, Long>, JpaSpecificationExecutor<Foo> {
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.springframework.http.HttpStatus;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import java.util.List;
|
||||
|
@ -14,6 +15,11 @@ import java.util.List;
|
|||
@RestController("/foos")
|
||||
public class FooController {
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
System.out.println("test");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private FooRepository repo;
|
||||
|
||||
|
|
|
@ -3,10 +3,12 @@ package com.baeldung;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@EnableJpaRepositories("com.baeldung.persistence")
|
||||
public class Example1IntegrationTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -3,10 +3,12 @@ package com.baeldung;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@EnableJpaRepositories("com.baeldung.persistence")
|
||||
public class Example2IntegrationTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.baeldung;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
@ -7,6 +8,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@Ignore
|
||||
public class Spring5ApplicationIntegrationTest {
|
||||
|
||||
@Test
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.context.support.GenericWebApplicationContext;
|
||||
|
||||
|
@ -13,6 +14,7 @@ import com.baeldung.Spring5Application;
|
|||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Spring5Application.class)
|
||||
@EnableJpaRepositories("com.baeldung.persistence")
|
||||
public class BeanRegistrationIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.baeldung.jdbc.autogenkey;
|
|||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -15,6 +16,7 @@ import com.baeldung.jdbc.autogenkey.repository.MessageRepositoryJDBCTemplate;
|
|||
import com.baeldung.jdbc.autogenkey.repository.MessageRepositorySimpleJDBCInsert;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@Ignore
|
||||
public class GetAutoGenKeyByJDBC {
|
||||
|
||||
@Configuration
|
||||
|
|
|
@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue;
|
|||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -16,18 +17,15 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@Ignore
|
||||
public class JsonbIntegrationTest {
|
||||
@Value("${security.user.name}")
|
||||
private String username;
|
||||
@Value("${security.user.password}")
|
||||
private String password;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate template;
|
||||
|
||||
@Test
|
||||
public void givenId_whenUriIsPerson_thenGetPerson() {
|
||||
ResponseEntity<Person> response = template.withBasicAuth(username, password)
|
||||
ResponseEntity<Person> response = template
|
||||
.getForEntity("/person/1", Person.class);
|
||||
Person person = response.getBody();
|
||||
assertTrue(person.equals(new Person(2, "Jhon", "jhon1@test.com", 0, LocalDate.of(2019, 9, 9), BigDecimal.valueOf(1500.0))));
|
||||
|
@ -35,8 +33,8 @@ public class JsonbIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void whenSendPostAPerson_thenGetOkStatus() {
|
||||
ResponseEntity<Boolean> response = template.withBasicAuth(username, password)
|
||||
.postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\",\"id\":10}", Boolean.class);
|
||||
ResponseEntity<Boolean> response = template.withBasicAuth("user","password").
|
||||
postForEntity("/person", "{\"birthDate\":\"07-09-2017\",\"email\":\"jhon1@test.com\",\"person-name\":\"Jhon\",\"id\":10}", Boolean.class);
|
||||
assertTrue(response.getBody());
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.baeldung.security;
|
|||
|
||||
import com.baeldung.SpringSecurity5Application;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -31,6 +32,7 @@ public class SecurityIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@WithMockUser
|
||||
public void whenHasCredentials_thenSeesGreeting() {
|
||||
this.rest.get().uri("/").exchange().expectStatus().isOk().expectBody(String.class).isEqualTo("Hello, user");
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.function.server.RequestPredicates;
|
||||
|
@ -16,6 +17,7 @@ import reactor.core.publisher.Mono;
|
|||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Spring5Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@EnableJpaRepositories("com.baeldung.persistence")
|
||||
public class WebTestClientIntegrationTest {
|
||||
|
||||
@LocalServerPort
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.springframework.web.servlet.ModelAndView;
|
|||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration({"classpath:test-mvc.xml"})
|
||||
public class PassParametersControllerTest {
|
||||
public class PassParametersControllerIntegrationTest {
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
|
@ -5,9 +5,9 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
|
||||
public interface ITransactionalTest {
|
||||
public interface ITransactionalUnitTest {
|
||||
|
||||
Logger log = LoggerFactory.getLogger(ITransactionalTest.class);
|
||||
Logger log = LoggerFactory.getLogger(ITransactionalUnitTest.class);
|
||||
|
||||
@BeforeTransaction
|
||||
default void beforeTransaction() {
|
|
@ -5,7 +5,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
@ContextConfiguration(classes = TransactionalTestConfiguration.class)
|
||||
public class TransactionalIntegrationTest extends AbstractTransactionalJUnit4SpringContextTests implements ITransactionalTest {
|
||||
public class TransactionalIntegrationTest extends AbstractTransactionalJUnit4SpringContextTests implements ITransactionalUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenDefaultMethodAnnotatedWithBeforeTransaction_thenDefaultMethodIsExecuted() {
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
### The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters)
|
||||
- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder)
|
||||
- [Introduction to WebJars](http://www.baeldung.com/maven-webjars)
|
||||
- [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper)
|
||||
- [Shutdown a Spring Boot Application](http://www.baeldung.com/spring-boot-shutdown)
|
||||
- [Create a Fat Jar App with Spring Boot](http://www.baeldung.com/deployable-fat-jar-spring-boot)
|
||||
- [Spring Boot Dependency Management with a Custom Parent](http://www.baeldung.com/spring-boot-dependency-management-custom-parent)
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
### The Course
|
||||
The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters)
|
||||
- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder)
|
||||
- [Introduction to WebJars](http://www.baeldung.com/maven-webjars)
|
||||
- [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper)
|
||||
- [Shutdown a Spring Boot Application](http://www.baeldung.com/spring-boot-shutdown)
|
||||
- [Create a Fat Jar App with Spring Boot](http://www.baeldung.com/deployable-fat-jar-spring-boot)
|
||||
- [Spring Boot Dependency Management with a Custom Parent](http://www.baeldung.com/spring-boot-dependency-management-custom-parent)
|
|
@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class KubernetesBackendApplicationTests {
|
||||
public class KubernetesBackendApplicationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
|
@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class KubernetesFrontendApplicationTests {
|
||||
public class KubernetesFrontendApplicationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.annotation;
|
||||
package com.baeldung.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
|
@ -1,10 +1,10 @@
|
|||
package org.baeldung.config;
|
||||
package com.baeldung.config;
|
||||
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoClient;
|
||||
import org.baeldung.converter.UserWriterConverter;
|
||||
import org.baeldung.event.CascadeSaveMongoEventListener;
|
||||
import org.baeldung.event.UserCascadeSaveMongoEventListener;
|
||||
import com.baeldung.converter.UserWriterConverter;
|
||||
import com.baeldung.event.CascadeSaveMongoEventListener;
|
||||
import com.baeldung.event.UserCascadeSaveMongoEventListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
@ -17,7 +17,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@EnableMongoRepositories(basePackages = "org.baeldung.repository")
|
||||
@EnableMongoRepositories(basePackages = "com.baeldung.repository")
|
||||
public class MongoConfig extends AbstractMongoConfiguration {
|
||||
|
||||
private final List<Converter<?, ?>> converters = new ArrayList<Converter<?, ?>>();
|
||||
|
@ -34,7 +34,7 @@ public class MongoConfig extends AbstractMongoConfiguration {
|
|||
|
||||
@Override
|
||||
public String getMappingBasePackage() {
|
||||
return "org.baeldung";
|
||||
return "com.baeldung";
|
||||
}
|
||||
|
||||
@Bean
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.config;
|
||||
package com.baeldung.config;
|
||||
|
||||
import com.mongodb.Mongo;
|
||||
import com.mongodb.MongoClient;
|
||||
|
@ -8,7 +8,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
|
|||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableMongoRepositories(basePackages = "org.baeldung.repository")
|
||||
@EnableMongoRepositories(basePackages = "com.baeldung.repository")
|
||||
public class SimpleMongoConfig {
|
||||
|
||||
@Bean
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.converter;
|
||||
package com.baeldung.converter;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.model.User;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.event;
|
||||
package com.baeldung.event;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.baeldung.annotation.CascadeSave;
|
||||
import com.baeldung.annotation.CascadeSave;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
||||
import org.springframework.data.mongodb.core.mapping.DBRef;
|
||||
import org.springframework.util.ReflectionUtils;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.event;
|
||||
package com.baeldung.event;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.event;
|
||||
package com.baeldung.event;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.baeldung.event;
|
||||
package com.baeldung.event;
|
||||
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.model.User;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.MongoOperations;
|
||||
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.model;
|
||||
package com.baeldung.model;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
|
@ -1,6 +1,6 @@
|
|||
package org.baeldung.model;
|
||||
package com.baeldung.model;
|
||||
|
||||
import org.baeldung.annotation.CascadeSave;
|
||||
import com.baeldung.annotation.CascadeSave;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
|
@ -1,6 +1,6 @@
|
|||
package org.baeldung.repository;
|
||||
package com.baeldung.repository;
|
||||
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.model.User;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
|
@ -1,12 +1,12 @@
|
|||
package org.baeldung.aggregation;
|
||||
package com.baeldung.aggregation;
|
||||
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.DBCollection;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.util.JSON;
|
||||
import org.baeldung.aggregation.model.StatePopulation;
|
||||
import org.baeldung.config.MongoConfig;
|
||||
import com.baeldung.aggregation.model.StatePopulation;
|
||||
import com.baeldung.config.MongoConfig;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.aggregation.model;
|
||||
package com.baeldung.aggregation.model;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.baeldung.gridfs;
|
||||
package com.baeldung.gridfs;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.mongotemplate;
|
||||
package com.baeldung.mongotemplate;
|
||||
|
||||
import org.baeldung.config.MongoConfig;
|
||||
import org.baeldung.model.EmailAddress;
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.config.MongoConfig;
|
||||
import com.baeldung.model.EmailAddress;
|
||||
import com.baeldung.model.User;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
|
@ -1,7 +1,7 @@
|
|||
package org.baeldung.mongotemplate;
|
||||
package com.baeldung.mongotemplate;
|
||||
|
||||
import org.baeldung.config.SimpleMongoConfig;
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.config.SimpleMongoConfig;
|
||||
import com.baeldung.model.User;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
|
@ -1,8 +1,8 @@
|
|||
package org.baeldung.mongotemplate;
|
||||
package com.baeldung.mongotemplate;
|
||||
|
||||
import org.baeldung.config.MongoConfig;
|
||||
import org.baeldung.model.EmailAddress;
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.config.MongoConfig;
|
||||
import com.baeldung.model.EmailAddress;
|
||||
import com.baeldung.model.User;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
|
@ -1,7 +1,7 @@
|
|||
package org.baeldung.repository;
|
||||
package com.baeldung.repository;
|
||||
|
||||
import org.baeldung.model.User;
|
||||
import org.baeldung.repository.UserRepository;
|
||||
import com.baeldung.model.User;
|
||||
import com.baeldung.repository.UserRepository;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -1,13 +1,13 @@
|
|||
package org.baeldung.repository;
|
||||
package com.baeldung.repository;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.config.MongoConfig;
|
||||
import org.baeldung.model.QUser;
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.config.MongoConfig;
|
||||
import com.baeldung.model.QUser;
|
||||
import com.baeldung.model.User;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
|
@ -1,12 +1,12 @@
|
|||
package org.baeldung.repository;
|
||||
package com.baeldung.repository;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.config.MongoConfig;
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.config.MongoConfig;
|
||||
import com.baeldung.model.User;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
|
@ -1,12 +1,12 @@
|
|||
package org.baeldung.repository;
|
||||
package com.baeldung.repository;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.config.MongoConfig;
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.config.MongoConfig;
|
||||
import com.baeldung.model.User;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
|
@ -1,12 +1,12 @@
|
|||
package org.baeldung.repository;
|
||||
package com.baeldung.repository;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.config.MongoConfig;
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.config.MongoConfig;
|
||||
import com.baeldung.model.User;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
|
@ -1,9 +1,9 @@
|
|||
package org.baeldung.repository;
|
||||
package com.baeldung.repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.baeldung.config.MongoConfig;
|
||||
import org.baeldung.model.User;
|
||||
import com.baeldung.config.MongoConfig;
|
||||
import com.baeldung.model.User;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
|
@ -7,7 +7,7 @@ import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
|
|||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class AuthorEventHandlerTest {
|
||||
public class AuthorEventHandlerUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenCreateAuthorThenSuccess() {
|
|
@ -7,7 +7,7 @@ import org.mockito.Mockito;
|
|||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class BookEventHandlerTest {
|
||||
public class BookEventHandlerUnitTest {
|
||||
@Test
|
||||
public void whenCreateBookThenSuccess() {
|
||||
Book book = mock(Book.class);
|
|
@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|||
|
||||
import com.baeldung.web.controller.SimpleBookController;
|
||||
|
||||
public class SimpleBookControllerTest {
|
||||
public class SimpleBookControllerIntegrationTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
|
|
@ -12,7 +12,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|||
|
||||
import com.baeldung.web.controller.SimpleBookController;
|
||||
|
||||
public class SimpleBookRestControllerTest {
|
||||
public class SimpleBookRestControllerIntegrationTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
|
|
@ -6,9 +6,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
|||
|
||||
@Configuration
|
||||
@ComponentScan("org.baeldung.test")
|
||||
public class ConfigTest extends WebMvcConfigurerAdapter {
|
||||
public class ConfigIntegrationTest extends WebMvcConfigurerAdapter {
|
||||
|
||||
public ConfigTest() {
|
||||
public ConfigIntegrationTest() {
|
||||
super();
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
|||
|
||||
import org.baeldung.common.web.AbstractDiscoverabilityLiveTest;
|
||||
import org.baeldung.persistence.model.Foo;
|
||||
import org.baeldung.spring.ConfigTest;
|
||||
import org.baeldung.spring.ConfigIntegrationTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = { ConfigIntegrationTest.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ActiveProfiles("test")
|
||||
public class FooDiscoverabilityLiveTest extends AbstractDiscoverabilityLiveTest<Foo> {
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
|||
|
||||
import org.baeldung.common.web.AbstractBasicLiveTest;
|
||||
import org.baeldung.persistence.model.Foo;
|
||||
import org.baeldung.spring.ConfigTest;
|
||||
import org.baeldung.spring.ConfigIntegrationTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = { ConfigIntegrationTest.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ActiveProfiles("test")
|
||||
public class FooLiveTest extends AbstractBasicLiveTest<Foo> {
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
|
||||
import org.baeldung.common.web.AbstractBasicLiveTest;
|
||||
import org.baeldung.persistence.model.Foo;
|
||||
import org.baeldung.spring.ConfigTest;
|
||||
import org.baeldung.spring.ConfigIntegrationTest;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
@ -22,7 +22,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = { ConfigIntegrationTest.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ActiveProfiles("test")
|
||||
public class FooPageableLiveTest extends AbstractBasicLiveTest<Foo> {
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import com.baeldung.propertyeditor.creditcard.CreditCard;
|
|||
import com.baeldung.propertyeditor.creditcard.CreditCardEditor;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CreditCardEditorTest {
|
||||
public class CreditCardEditorUnitTest {
|
||||
|
||||
private CreditCardEditor creditCardEditor;
|
||||
|
|
@ -11,7 +11,7 @@ import org.springframework.web.context.WebApplicationContext;
|
|||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SpringSecurityThymeleafApplicationTests {
|
||||
public class SpringSecurityThymeleafApplicationIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
ViewController viewController;
|
|
@ -20,12 +20,12 @@ public class RegisterExtensionSampleExtension implements BeforeAllCallback, Befo
|
|||
|
||||
@Override
|
||||
public void beforeAll(ExtensionContext extensionContext) throws Exception {
|
||||
logger.info("Type " + type + " In beforeAll : " + extensionContext.getDisplayName());
|
||||
logger.info("Type {} In beforeAll : {}", type, extensionContext.getDisplayName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeEach(ExtensionContext extensionContext) throws Exception {
|
||||
logger.info("Type " + type + " In beforeEach : " + extensionContext.getDisplayName());
|
||||
logger.info("Type {} In beforeEach : {}", type, extensionContext.getDisplayName());
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
|
|
|
@ -13,7 +13,7 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
public class FutureTest {
|
||||
public class FutureUnitTest {
|
||||
|
||||
private static final String error = "Failed to get underlying value.";
|
||||
private static final String HELLO = "Welcome to Baeldung!";
|
Loading…
Reference in New Issue