repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
nvinayshetty/DTOnator | src/test/com/nvinayshetty/DTOnator/fieldRepresentors/DoubleFieldRepresentorShould.java | // Path: src/com/nvinayshetty/DTOnator/FieldRepresentors/DoubleFieldRepresentor.java
// public class DoubleFieldRepresentor extends FieldRepresentor {
// @Override
// public String getFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return accessModifier.getModifier() + "double" + suffix(key);
//
// }
//
// @Override
// protected String getKotlinValFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return "val " + key + " :Double";
// }
//
// @Override
// protected String getKotlinVarFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return "val " + key + " :Double";
// }
//
// }
| import com.nvinayshetty.DTOnator.FieldCreator.AccessModifier;
import com.nvinayshetty.DTOnator.FieldRepresentors.DoubleFieldRepresentor;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.fieldRepresentors;
/**
* Created by vinay on 1/8/15.
*/
public class DoubleFieldRepresentorShould {
private String fieldName;
@Test
public void CreatePublicFieldWhenAcessModifierIsPublic() {
fieldName = "valid"; | // Path: src/com/nvinayshetty/DTOnator/FieldRepresentors/DoubleFieldRepresentor.java
// public class DoubleFieldRepresentor extends FieldRepresentor {
// @Override
// public String getFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return accessModifier.getModifier() + "double" + suffix(key);
//
// }
//
// @Override
// protected String getKotlinValFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return "val " + key + " :Double";
// }
//
// @Override
// protected String getKotlinVarFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return "val " + key + " :Double";
// }
//
// }
// Path: src/test/com/nvinayshetty/DTOnator/fieldRepresentors/DoubleFieldRepresentorShould.java
import com.nvinayshetty.DTOnator.FieldCreator.AccessModifier;
import com.nvinayshetty.DTOnator.FieldRepresentors.DoubleFieldRepresentor;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.fieldRepresentors;
/**
* Created by vinay on 1/8/15.
*/
public class DoubleFieldRepresentorShould {
private String fieldName;
@Test
public void CreatePublicFieldWhenAcessModifierIsPublic() {
fieldName = "valid"; | String actual = new DoubleFieldRepresentor().getFieldRepresentationFor(AccessModifier.PUBLIC, fieldName); |
nvinayshetty/DTOnator | src/com/nvinayshetty/DTOnator/ClassCreator/EncapsulatedClassCreator.java | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldEncapsulationOptions.java
// public enum FieldEncapsulationOptions {
// PROVIDE_GETTER, PROVIDE_SETTER, PROVIDE_PRIVATE_FIELD
// }
//
// Path: src/com/nvinayshetty/DTOnator/NameConventionCommands/FieldNameParser.java
// public class FieldNameParser {
// HashSet<NameParserCommand> nameParserCommands;
//
// public FieldNameParser(HashSet<NameParserCommand> nameParserCommands) {
// this.nameParserCommands = nameParserCommands;
// }
//
// public String parseField(String field) {
// if (nameParserCommands == null)
// return field;
// String parsedFieldName = field;//= field;
// Iterator<NameParserCommand> fieldParserIterator = nameParserCommands.iterator();
// while (fieldParserIterator.hasNext()) {
// NameParserCommand parser = fieldParserIterator.next();
// parsedFieldName = parser.parseFieldName(parsedFieldName);
// }
// return parsedFieldName;
// }
//
// public String undo(String fieldName) {
// if (nameParserCommands == null)
// return fieldName;
// String unparsed = fieldName;//= field;
// Iterator<NameParserCommand> fieldParserIterator = nameParserCommands.iterator();
// while (fieldParserIterator.hasNext()) {
// NameParserCommand parser = fieldParserIterator.next();
// unparsed = parser.undoParsing(unparsed);
// }
// return unparsed;
// }
// }
| import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiField;
import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldEncapsulationOptions;
import com.nvinayshetty.DTOnator.NameConventionCommands.FieldNameParser;
import java.util.EnumSet; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nvinayshetty.DTOnator.ClassCreator;
/**
* Created by vinay on 7/6/15.
*/
public class EncapsulatedClassCreator {
EnumSet<FieldEncapsulationOptions> fieldEncapsulationOptions; | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldEncapsulationOptions.java
// public enum FieldEncapsulationOptions {
// PROVIDE_GETTER, PROVIDE_SETTER, PROVIDE_PRIVATE_FIELD
// }
//
// Path: src/com/nvinayshetty/DTOnator/NameConventionCommands/FieldNameParser.java
// public class FieldNameParser {
// HashSet<NameParserCommand> nameParserCommands;
//
// public FieldNameParser(HashSet<NameParserCommand> nameParserCommands) {
// this.nameParserCommands = nameParserCommands;
// }
//
// public String parseField(String field) {
// if (nameParserCommands == null)
// return field;
// String parsedFieldName = field;//= field;
// Iterator<NameParserCommand> fieldParserIterator = nameParserCommands.iterator();
// while (fieldParserIterator.hasNext()) {
// NameParserCommand parser = fieldParserIterator.next();
// parsedFieldName = parser.parseFieldName(parsedFieldName);
// }
// return parsedFieldName;
// }
//
// public String undo(String fieldName) {
// if (nameParserCommands == null)
// return fieldName;
// String unparsed = fieldName;//= field;
// Iterator<NameParserCommand> fieldParserIterator = nameParserCommands.iterator();
// while (fieldParserIterator.hasNext()) {
// NameParserCommand parser = fieldParserIterator.next();
// unparsed = parser.undoParsing(unparsed);
// }
// return unparsed;
// }
// }
// Path: src/com/nvinayshetty/DTOnator/ClassCreator/EncapsulatedClassCreator.java
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElementFactory;
import com.intellij.psi.PsiField;
import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldEncapsulationOptions;
import com.nvinayshetty.DTOnator.NameConventionCommands.FieldNameParser;
import java.util.EnumSet;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nvinayshetty.DTOnator.ClassCreator;
/**
* Created by vinay on 7/6/15.
*/
public class EncapsulatedClassCreator {
EnumSet<FieldEncapsulationOptions> fieldEncapsulationOptions; | FieldNameParser nameParser; |
nvinayshetty/DTOnator | src/com/nvinayshetty/DTOnator/FeedValidator/InputFeedValidationFactory.java | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FeedType.java
// public enum FeedType {
// JSON
// }
| import com.nvinayshetty.DTOnator.DtoCreationOptions.FeedType;
import org.json.JSONException;
import javax.swing.*; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nvinayshetty.DTOnator.FeedValidator;
/**
* Created by vinay on 30/5/15.
*/
public class InputFeedValidationFactory implements FeedValidator {
FeedValidator feedValidator;
| // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FeedType.java
// public enum FeedType {
// JSON
// }
// Path: src/com/nvinayshetty/DTOnator/FeedValidator/InputFeedValidationFactory.java
import com.nvinayshetty.DTOnator.DtoCreationOptions.FeedType;
import org.json.JSONException;
import javax.swing.*;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nvinayshetty.DTOnator.FeedValidator;
/**
* Created by vinay on 30/5/15.
*/
public class InputFeedValidationFactory implements FeedValidator {
FeedValidator feedValidator;
| public InputFeedValidationFactory(FeedType feedType) { |
nvinayshetty/DTOnator | src/test/com/nvinayshetty/DTOnator/fieldRepresentors/StringFieldRepresentorShould.java | // Path: src/com/nvinayshetty/DTOnator/FieldRepresentors/StringFieldRepresentor.java
// public class StringFieldRepresentor extends FieldRepresentor {
// @Override
// public String getFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return accessModifier.getModifier() + "String" + suffix(key);
// }
//
// @Override
// protected String getKotlinValFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return "val " + key + " :String" + "\n";
// }
//
// @Override
// protected String getKotlinVarFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return "val " + key + " :String";
// }
//
//
// }
| import static junit.framework.TestCase.assertEquals;
import com.nvinayshetty.DTOnator.FieldCreator.AccessModifier;
import com.nvinayshetty.DTOnator.FieldRepresentors.StringFieldRepresentor;
import org.junit.Test; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.fieldRepresentors;
/**
* Created by vinay on 1/8/15.
*/
public class StringFieldRepresentorShould {
private String fieldName;
@Test
public void CreatePublicFieldWhenAcessModifierIsPublic() {
fieldName = "valid"; | // Path: src/com/nvinayshetty/DTOnator/FieldRepresentors/StringFieldRepresentor.java
// public class StringFieldRepresentor extends FieldRepresentor {
// @Override
// public String getFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return accessModifier.getModifier() + "String" + suffix(key);
// }
//
// @Override
// protected String getKotlinValFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return "val " + key + " :String" + "\n";
// }
//
// @Override
// protected String getKotlinVarFieldRepresentationFor(AccessModifier accessModifier, String key) {
// return "val " + key + " :String";
// }
//
//
// }
// Path: src/test/com/nvinayshetty/DTOnator/fieldRepresentors/StringFieldRepresentorShould.java
import static junit.framework.TestCase.assertEquals;
import com.nvinayshetty.DTOnator.FieldCreator.AccessModifier;
import com.nvinayshetty.DTOnator.FieldRepresentors.StringFieldRepresentor;
import org.junit.Test;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.fieldRepresentors;
/**
* Created by vinay on 1/8/15.
*/
public class StringFieldRepresentorShould {
private String fieldName;
@Test
public void CreatePublicFieldWhenAcessModifierIsPublic() {
fieldName = "valid"; | String actual = new StringFieldRepresentor().getFieldRepresentationFor(AccessModifier.PUBLIC, fieldName); |
nvinayshetty/DTOnator | src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
| import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){ | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
// Path: src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java
import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){ | FieldCreationStrategy fieldCreationStrategy= FieldCreationFactory.getFieldCreatorFor(FieldType.GSON,""); |
nvinayshetty/DTOnator | src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
| import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){ | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
// Path: src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java
import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){ | FieldCreationStrategy fieldCreationStrategy= FieldCreationFactory.getFieldCreatorFor(FieldType.GSON,""); |
nvinayshetty/DTOnator | src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
| import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){ | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
// Path: src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java
import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){ | FieldCreationStrategy fieldCreationStrategy= FieldCreationFactory.getFieldCreatorFor(FieldType.GSON,""); |
nvinayshetty/DTOnator | src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
| import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){
FieldCreationStrategy fieldCreationStrategy= FieldCreationFactory.getFieldCreatorFor(FieldType.GSON,""); | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
// Path: src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java
import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){
FieldCreationStrategy fieldCreationStrategy= FieldCreationFactory.getFieldCreatorFor(FieldType.GSON,""); | assertTrue(fieldCreationStrategy instanceof GsonFieldCreator); |
nvinayshetty/DTOnator | src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
| import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){
FieldCreationStrategy fieldCreationStrategy= FieldCreationFactory.getFieldCreatorFor(FieldType.GSON,"");
assertTrue(fieldCreationStrategy instanceof GsonFieldCreator);
FieldCreationStrategy SimpleFieldCreationStrategy= FieldCreationFactory.getFieldCreatorFor(FieldType.POJO,""); | // Path: src/com/nvinayshetty/DTOnator/DtoCreationOptions/FieldType.java
// public enum FieldType {
// GSON, POJO,GSON_EXPOSE,JACKSON,CUSTOM,AUTO_VALUE
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactory.java
// public class FieldCreationFactory {
// public static FieldCreationStrategy getFieldCreatorFor(FieldType fieldType,String cutomFiledPattern) {
// switch (fieldType) {
// case AUTO_VALUE:
// return new AutoValueFieldCreator();
// case GSON:
// return new GsonFieldCreator();
// case POJO:
// return new SimpleFieldCreator();
// case GSON_EXPOSE:
// return new ExposedGsonFieldCreator();
// case JACKSON:
// return new JacksonFieldCreator();
// case CUSTOM:
// return new CustomFieldCreator(cutomFiledPattern);
//
//
// }
// return null;
// }
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationStrategy.java
// public interface FieldCreationStrategy {
// String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver);
//
// String getImportDirective();
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/GsonFieldCreator.java
// public class GsonFieldCreator implements FieldCreationStrategy {
//
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor type, AccessModifier modifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return type.gsonFieldRepresentationTemplate(languageType, modifier, key, parser, nameConflictResolver);
// }
//
// @Override
// public String getImportDirective() {
// return "com.google.gson.annotations.SerializedName";
// }
//
// }
//
// Path: src/com/nvinayshetty/DTOnator/FieldCreator/SimpleFieldCreator.java
// public class SimpleFieldCreator implements FieldCreationStrategy {
// @Override
// public String getFieldFor(LanguageType languageType, FieldRepresentor fieldRepresentor, AccessModifier accessModifier, String key, FieldNameParser parser, NameConflictResolver nameConflictResolver) {
// return fieldRepresentor.fieldCreationTemplate(languageType,accessModifier, key, parser, nameConflictResolver, new KeywordClassifier());
// }
//
// @Override
// public String getImportDirective() {
// return "";
// }
//
//
// }
// Path: src/test/com/nvinayshetty/DTOnator/FieldCreator/FieldCreationFactoryShould.java
import com.nvinayshetty.DTOnator.DtoCreationOptions.FieldType;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationFactory;
import com.nvinayshetty.DTOnator.FieldCreator.FieldCreationStrategy;
import com.nvinayshetty.DTOnator.FieldCreator.GsonFieldCreator;
import com.nvinayshetty.DTOnator.FieldCreator.SimpleFieldCreator;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FieldCreator;
/**
* Created by vinay on 16/8/15.
*/
public class FieldCreationFactoryShould {
@Test
public void shouldCretaGsonFieldWhenUserInputIsGson(){
FieldCreationStrategy fieldCreationStrategy= FieldCreationFactory.getFieldCreatorFor(FieldType.GSON,"");
assertTrue(fieldCreationStrategy instanceof GsonFieldCreator);
FieldCreationStrategy SimpleFieldCreationStrategy= FieldCreationFactory.getFieldCreatorFor(FieldType.POJO,""); | assertTrue(SimpleFieldCreationStrategy instanceof SimpleFieldCreator); |
nvinayshetty/DTOnator | src/test/com/nvinayshetty/DTOnator/FeedValidator/KeyworldClassifierShould.java | // Path: src/com/nvinayshetty/DTOnator/FeedValidator/KeywordClassifier.java
// public class KeywordClassifier {
// private HashSet<String> javaKeywords = new HashSet<String>();
//
// public void initKeywords() {
// javaKeywords.add("abstract");
// javaKeywords.add("continue");
// javaKeywords.add("for");
// javaKeywords.add("new");
// javaKeywords.add("switch");
// javaKeywords.add("assert");
// javaKeywords.add("default");
// javaKeywords.add("goto");
// javaKeywords.add("package");
// javaKeywords.add("synchronized");
// javaKeywords.add("boolean");
// javaKeywords.add("do");
// javaKeywords.add("if");
// javaKeywords.add("private");
// javaKeywords.add("this");
// javaKeywords.add("byte");
// javaKeywords.add("break");
// javaKeywords.add("double");
// javaKeywords.add("implements");
// javaKeywords.add("protected");
// javaKeywords.add("throw");
// javaKeywords.add("else");
// javaKeywords.add("import");
// javaKeywords.add("public");
// javaKeywords.add("throws");
// javaKeywords.add("case");
// javaKeywords.add("enum");
// javaKeywords.add("instanceof");
// javaKeywords.add("return");
// javaKeywords.add("transient");
// javaKeywords.add("catch");
// javaKeywords.add("char");
// javaKeywords.add("extends");
// javaKeywords.add("int");
// javaKeywords.add("short");
// javaKeywords.add("try");
// javaKeywords.add("final");
// javaKeywords.add("interface");
// javaKeywords.add("static");
// javaKeywords.add("void");
// javaKeywords.add("class");
// javaKeywords.add("finally");
// javaKeywords.add("long");
// javaKeywords.add("strictfp");
// javaKeywords.add("volatile");
// javaKeywords.add("const");
// javaKeywords.add("float");
// javaKeywords.add("native");
// javaKeywords.add("super");
// javaKeywords.add("while");
// javaKeywords.add("true");
// javaKeywords.add("false");
// javaKeywords.add("null");
// }
//
// public boolean isValidJavaIdentifier(String string) {
// initKeywords();
// if (string.isEmpty()) {
// return false;
// }
// if (!Character.isJavaIdentifierStart(string.charAt(0))) {
// return false;
// }
// for (int i = 1; i < string.length(); i++) {
// if (!Character.isJavaIdentifierPart(string.charAt(i))) {
// return false;
// }
// }
// return !javaKeywords.contains(string);
// }
//
//
// }
| import com.nvinayshetty.DTOnator.FeedValidator.KeywordClassifier;
import org.junit.Test; | /*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FeedValidator;
/**
* Created by vinay on 1/8/15.
*/
public class KeyworldClassifierShould {
@Test
public void removeAllInvalidCharactersInIdentifierShouldRemoveAllSpaces() { | // Path: src/com/nvinayshetty/DTOnator/FeedValidator/KeywordClassifier.java
// public class KeywordClassifier {
// private HashSet<String> javaKeywords = new HashSet<String>();
//
// public void initKeywords() {
// javaKeywords.add("abstract");
// javaKeywords.add("continue");
// javaKeywords.add("for");
// javaKeywords.add("new");
// javaKeywords.add("switch");
// javaKeywords.add("assert");
// javaKeywords.add("default");
// javaKeywords.add("goto");
// javaKeywords.add("package");
// javaKeywords.add("synchronized");
// javaKeywords.add("boolean");
// javaKeywords.add("do");
// javaKeywords.add("if");
// javaKeywords.add("private");
// javaKeywords.add("this");
// javaKeywords.add("byte");
// javaKeywords.add("break");
// javaKeywords.add("double");
// javaKeywords.add("implements");
// javaKeywords.add("protected");
// javaKeywords.add("throw");
// javaKeywords.add("else");
// javaKeywords.add("import");
// javaKeywords.add("public");
// javaKeywords.add("throws");
// javaKeywords.add("case");
// javaKeywords.add("enum");
// javaKeywords.add("instanceof");
// javaKeywords.add("return");
// javaKeywords.add("transient");
// javaKeywords.add("catch");
// javaKeywords.add("char");
// javaKeywords.add("extends");
// javaKeywords.add("int");
// javaKeywords.add("short");
// javaKeywords.add("try");
// javaKeywords.add("final");
// javaKeywords.add("interface");
// javaKeywords.add("static");
// javaKeywords.add("void");
// javaKeywords.add("class");
// javaKeywords.add("finally");
// javaKeywords.add("long");
// javaKeywords.add("strictfp");
// javaKeywords.add("volatile");
// javaKeywords.add("const");
// javaKeywords.add("float");
// javaKeywords.add("native");
// javaKeywords.add("super");
// javaKeywords.add("while");
// javaKeywords.add("true");
// javaKeywords.add("false");
// javaKeywords.add("null");
// }
//
// public boolean isValidJavaIdentifier(String string) {
// initKeywords();
// if (string.isEmpty()) {
// return false;
// }
// if (!Character.isJavaIdentifierStart(string.charAt(0))) {
// return false;
// }
// for (int i = 1; i < string.length(); i++) {
// if (!Character.isJavaIdentifierPart(string.charAt(i))) {
// return false;
// }
// }
// return !javaKeywords.contains(string);
// }
//
//
// }
// Path: src/test/com/nvinayshetty/DTOnator/FeedValidator/KeyworldClassifierShould.java
import com.nvinayshetty.DTOnator.FeedValidator.KeywordClassifier;
import org.junit.Test;
/*
* Copyright (C) 2015 Vinaya Prasad N
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package test.com.nvinayshetty.DTOnator.FeedValidator;
/**
* Created by vinay on 1/8/15.
*/
public class KeyworldClassifierShould {
@Test
public void removeAllInvalidCharactersInIdentifierShouldRemoveAllSpaces() { | KeywordClassifier clasifier = new KeywordClassifier(); |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/spring2/Spring_2_Test.java | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
| import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals; | package me.chanjar.spring2;
@ContextConfiguration(classes = { FooImpl.class, LooImpl.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Spring_2_Test extends AbstractTestNGSpringContextTests {
@MockBean | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
// Path: mock/src/test/java/me/chanjar/spring2/Spring_2_Test.java
import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
package me.chanjar.spring2;
@ContextConfiguration(classes = { FooImpl.class, LooImpl.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Spring_2_Test extends AbstractTestNGSpringContextTests {
@MockBean | private Bar bar; |
chanjarster/spring-test-examples | mvc/src/test/java/me/chanjar/springboot2/BootMvc_2_Test.java | // Path: mvc/src/main/java/me/chanjar/web/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
| import me.chanjar.web.Foo;
import me.chanjar.web.FooController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.web.servlet.MockMvc;
import org.testng.annotations.Test;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | package me.chanjar.springboot2;
@WebMvcTest
@ContextConfiguration(classes = { FooController.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class BootMvc_2_Test extends AbstractTestNGSpringContextTests {
@Autowired
private MockMvc mvc;
@MockBean | // Path: mvc/src/main/java/me/chanjar/web/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
// Path: mvc/src/test/java/me/chanjar/springboot2/BootMvc_2_Test.java
import me.chanjar.web.Foo;
import me.chanjar.web.FooController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.web.servlet.MockMvc;
import org.testng.annotations.Test;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
package me.chanjar.springboot2;
@WebMvcTest
@ContextConfiguration(classes = { FooController.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class BootMvc_2_Test extends AbstractTestNGSpringContextTests {
@Autowired
private MockMvc mvc;
@MockBean | private Foo foo; |
chanjarster/spring-test-examples | rdbs/src/test/java/me/chanjar/spring2/Spring_2_IT.java | // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
| import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.spring2;
@ContextConfiguration(classes = Spring_2_IT_Configuration.class)
public class Spring_2_IT extends AbstractTransactionalTestNGSpringContextTests {
@Autowired | // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
// Path: rdbs/src/test/java/me/chanjar/spring2/Spring_2_IT.java
import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.spring2;
@ContextConfiguration(classes = Spring_2_IT_Configuration.class)
public class Spring_2_IT extends AbstractTransactionalTestNGSpringContextTests {
@Autowired | private FooRepository fooRepository; |
chanjarster/spring-test-examples | rdbs/src/test/java/me/chanjar/spring2/Spring_2_IT.java | // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
| import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.spring2;
@ContextConfiguration(classes = Spring_2_IT_Configuration.class)
public class Spring_2_IT extends AbstractTransactionalTestNGSpringContextTests {
@Autowired
private FooRepository fooRepository;
@Test
public void testSave() {
| // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
// Path: rdbs/src/test/java/me/chanjar/spring2/Spring_2_IT.java
import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.spring2;
@ContextConfiguration(classes = Spring_2_IT_Configuration.class)
public class Spring_2_IT extends AbstractTransactionalTestNGSpringContextTests {
@Autowired
private FooRepository fooRepository;
@Test
public void testSave() {
| Foo foo = new Foo(); |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/testng/ex1/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
| import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.testng.ex1;
public class FooServiceImplTest {
@Test
public void testPlusCount() { | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
// Path: basic/src/test/java/me/chanjar/basic/testng/ex1/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.testng.ex1;
public class FooServiceImplTest {
@Test
public void testPlusCount() { | FooService foo = new FooServiceImpl(); |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/testng/ex1/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
| import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.testng.ex1;
public class FooServiceImplTest {
@Test
public void testPlusCount() { | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
// Path: basic/src/test/java/me/chanjar/basic/testng/ex1/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.testng.ex1;
public class FooServiceImplTest {
@Test
public void testPlusCount() { | FooService foo = new FooServiceImpl(); |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/activeprofiles/ex2/ActiveProfileTest.java | // Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Config.java
// @Configuration
// public class Config {
//
// @Bean
// @Profile("dev")
// public Foo fooDev() {
// return new Foo("dev");
// }
//
// @Bean
// @Profile("product")
// public Foo fooProduct() {
// return new Foo("product");
// }
//
// @Bean
// @Profile("default")
// public Foo fooDefault() {
// return new Foo("default");
// }
//
// @Bean
// public Bar bar() {
// return new Bar("no profile");
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
| import me.chanjar.annotation.activeprofiles.Bar;
import me.chanjar.annotation.activeprofiles.Config;
import me.chanjar.annotation.activeprofiles.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.annotation.activeprofiles.ex2;
@ContextConfiguration(classes = Config.class)
@ActiveProfiles("product")
public class ActiveProfileTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Config.java
// @Configuration
// public class Config {
//
// @Bean
// @Profile("dev")
// public Foo fooDev() {
// return new Foo("dev");
// }
//
// @Bean
// @Profile("product")
// public Foo fooProduct() {
// return new Foo("product");
// }
//
// @Bean
// @Profile("default")
// public Foo fooDefault() {
// return new Foo("default");
// }
//
// @Bean
// public Bar bar() {
// return new Bar("no profile");
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
// Path: annotation/src/test/java/me/chanjar/annotation/activeprofiles/ex2/ActiveProfileTest.java
import me.chanjar.annotation.activeprofiles.Bar;
import me.chanjar.annotation.activeprofiles.Config;
import me.chanjar.annotation.activeprofiles.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.annotation.activeprofiles.ex2;
@ContextConfiguration(classes = Config.class)
@ActiveProfiles("product")
public class ActiveProfileTest extends AbstractTestNGSpringContextTests {
@Autowired | private Foo foo; |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/activeprofiles/ex2/ActiveProfileTest.java | // Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Config.java
// @Configuration
// public class Config {
//
// @Bean
// @Profile("dev")
// public Foo fooDev() {
// return new Foo("dev");
// }
//
// @Bean
// @Profile("product")
// public Foo fooProduct() {
// return new Foo("product");
// }
//
// @Bean
// @Profile("default")
// public Foo fooDefault() {
// return new Foo("default");
// }
//
// @Bean
// public Bar bar() {
// return new Bar("no profile");
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
| import me.chanjar.annotation.activeprofiles.Bar;
import me.chanjar.annotation.activeprofiles.Config;
import me.chanjar.annotation.activeprofiles.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.annotation.activeprofiles.ex2;
@ContextConfiguration(classes = Config.class)
@ActiveProfiles("product")
public class ActiveProfileTest extends AbstractTestNGSpringContextTests {
@Autowired
private Foo foo;
@Autowired | // Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Config.java
// @Configuration
// public class Config {
//
// @Bean
// @Profile("dev")
// public Foo fooDev() {
// return new Foo("dev");
// }
//
// @Bean
// @Profile("product")
// public Foo fooProduct() {
// return new Foo("product");
// }
//
// @Bean
// @Profile("default")
// public Foo fooDefault() {
// return new Foo("default");
// }
//
// @Bean
// public Bar bar() {
// return new Bar("no profile");
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
// Path: annotation/src/test/java/me/chanjar/annotation/activeprofiles/ex2/ActiveProfileTest.java
import me.chanjar.annotation.activeprofiles.Bar;
import me.chanjar.annotation.activeprofiles.Config;
import me.chanjar.annotation.activeprofiles.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.annotation.activeprofiles.ex2;
@ContextConfiguration(classes = Config.class)
@ActiveProfiles("product")
public class ActiveProfileTest extends AbstractTestNGSpringContextTests {
@Autowired
private Foo foo;
@Autowired | private Bar bar; |
chanjarster/spring-test-examples | configuration/src/test/java/me/chanjar/configuration/ex1/FooConfigurationTest.java | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
| import me.chanjar.configuration.service.Foo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull; | package me.chanjar.configuration.ex1;
public class FooConfigurationTest {
private AnnotationConfigApplicationContext context;
@BeforeMethod
public void init() {
context = new AnnotationConfigApplicationContext();
}
@AfterMethod(alwaysRun = true)
public void reset() {
context.close();
}
@Test
public void testFooCreation() {
context.register(FooConfiguration.class);
context.refresh(); | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
// Path: configuration/src/test/java/me/chanjar/configuration/ex1/FooConfigurationTest.java
import me.chanjar.configuration.service.Foo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull;
package me.chanjar.configuration.ex1;
public class FooConfigurationTest {
private AnnotationConfigApplicationContext context;
@BeforeMethod
public void init() {
context = new AnnotationConfigApplicationContext();
}
@AfterMethod(alwaysRun = true)
public void reset() {
context.close();
}
@Test
public void testFooCreation() {
context.register(FooConfiguration.class);
context.refresh(); | assertNotNull(context.getBean(Foo.class)); |
chanjarster/spring-test-examples | configuration/src/test/java/me/chanjar/configuration/ex3/FooConfigurationTest.java | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
| import me.chanjar.configuration.service.Foo;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull; | package me.chanjar.configuration.ex3;
public class FooConfigurationTest {
private AnnotationConfigApplicationContext context;
@BeforeMethod
public void init() {
context = new AnnotationConfigApplicationContext();
}
@AfterMethod(alwaysRun = true)
public void reset() {
context.close();
}
@Test(expectedExceptions = NoSuchBeanDefinitionException.class)
public void testFooCreatePropertyNull() {
context.register(FooConfiguration.class);
context.refresh(); | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
// Path: configuration/src/test/java/me/chanjar/configuration/ex3/FooConfigurationTest.java
import me.chanjar.configuration.service.Foo;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.assertNotNull;
package me.chanjar.configuration.ex3;
public class FooConfigurationTest {
private AnnotationConfigApplicationContext context;
@BeforeMethod
public void init() {
context = new AnnotationConfigApplicationContext();
}
@AfterMethod(alwaysRun = true)
public void reset() {
context.close();
}
@Test(expectedExceptions = NoSuchBeanDefinitionException.class)
public void testFooCreatePropertyNull() {
context.register(FooConfiguration.class);
context.refresh(); | context.getBean(Foo.class); |
chanjarster/spring-test-examples | share-config/src/test/java/me/chanjar/shareconfig/annotation/FooRepositoryIT.java | // Path: share-config/src/test/java/me/chanjar/shareconfig/service/FooRepositoryTestBase.java
// public class FooRepositoryTestBase extends AbstractTransactionalTestNGSpringContextTests {
//
// @Autowired
// private FooRepository fooRepository;
//
// @Autowired
// private Flyway flyway;
//
// @Test
// public void testSave() {
//
// Foo foo = new Foo();
// foo.setName("Bob");
// fooRepository.save(foo);
//
// assertEquals(countRowsInTable("FOO"), 1);
// countRowsInTableWhere("FOO", "name = 'Bob'");
// }
//
// @Test(dependsOnMethods = "testSave")
// public void testDelete() {
//
// assertEquals(countRowsInTable("FOO"), 0);
//
// Foo foo = new Foo();
// foo.setName("Bob");
// fooRepository.save(foo);
//
// fooRepository.delete(foo.getName());
// assertEquals(countRowsInTable("FOO"), 0);
//
// }
//
// @AfterTest
// public void cleanDb() {
// flyway.clean();
// }
//
// }
| import me.chanjar.shareconfig.service.FooRepositoryTestBase;
import me.chanjar.shareconfig.testconfig.AnnotationConfiguration;
import org.springframework.boot.test.context.SpringBootTest; | package me.chanjar.shareconfig.annotation;
@SpringBootTest(classes = FooRepositoryIT.class)
@AnnotationConfiguration | // Path: share-config/src/test/java/me/chanjar/shareconfig/service/FooRepositoryTestBase.java
// public class FooRepositoryTestBase extends AbstractTransactionalTestNGSpringContextTests {
//
// @Autowired
// private FooRepository fooRepository;
//
// @Autowired
// private Flyway flyway;
//
// @Test
// public void testSave() {
//
// Foo foo = new Foo();
// foo.setName("Bob");
// fooRepository.save(foo);
//
// assertEquals(countRowsInTable("FOO"), 1);
// countRowsInTableWhere("FOO", "name = 'Bob'");
// }
//
// @Test(dependsOnMethods = "testSave")
// public void testDelete() {
//
// assertEquals(countRowsInTable("FOO"), 0);
//
// Foo foo = new Foo();
// foo.setName("Bob");
// fooRepository.save(foo);
//
// fooRepository.delete(foo.getName());
// assertEquals(countRowsInTable("FOO"), 0);
//
// }
//
// @AfterTest
// public void cleanDb() {
// flyway.clean();
// }
//
// }
// Path: share-config/src/test/java/me/chanjar/shareconfig/annotation/FooRepositoryIT.java
import me.chanjar.shareconfig.service.FooRepositoryTestBase;
import me.chanjar.shareconfig.testconfig.AnnotationConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
package me.chanjar.shareconfig.annotation;
@SpringBootTest(classes = FooRepositoryIT.class)
@AnnotationConfiguration | public class FooRepositoryIT extends FooRepositoryTestBase { |
chanjarster/spring-test-examples | configuration/src/test/java/me/chanjar/configuration/ex4/BarConfiguration.java | // Path: configuration/src/main/java/me/chanjar/configuration/service/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
| import me.chanjar.configuration.service.Bar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; | package me.chanjar.configuration.ex4;
@Configuration
@EnableConfigurationProperties(BarConfiguration.BarProperties.class)
public class BarConfiguration {
@Autowired
private BarProperties barProperties;
@Bean | // Path: configuration/src/main/java/me/chanjar/configuration/service/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: configuration/src/test/java/me/chanjar/configuration/ex4/BarConfiguration.java
import me.chanjar.configuration.service.Bar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
package me.chanjar.configuration.ex4;
@Configuration
@EnableConfigurationProperties(BarConfiguration.BarProperties.class)
public class BarConfiguration {
@Autowired
private BarProperties barProperties;
@Bean | public Bar bar() { |
chanjarster/spring-test-examples | share-config/src/main/java/me/chanjar/shareconfig/config/FooRepositoryConfiguration.java | // Path: share-config/src/main/java/me/chanjar/shareconfig/service/FooRepository.java
// public interface FooRepository {
// void save(Foo foo);
//
// void delete(String name);
// }
//
// Path: share-config/src/main/java/me/chanjar/shareconfig/service/FooRepositoryImpl.java
// public class FooRepositoryImpl implements FooRepository {
//
// private JdbcTemplate jdbcTemplate;
//
// @Override
// public void save(Foo foo) {
// jdbcTemplate.update("INSERT INTO FOO(name) VALUES (?)", foo.getName());
// }
//
// @Override
// public void delete(String name) {
// jdbcTemplate.update("DELETE FROM FOO WHERE NAME = ?", name);
// }
//
// public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
// this.jdbcTemplate = jdbcTemplate;
// }
//
// }
| import me.chanjar.shareconfig.service.FooRepository;
import me.chanjar.shareconfig.service.FooRepositoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate; | package me.chanjar.shareconfig.config;
@Configuration
public class FooRepositoryConfiguration {
@Autowired
private JdbcTemplate jdbcTemplate;
@Bean | // Path: share-config/src/main/java/me/chanjar/shareconfig/service/FooRepository.java
// public interface FooRepository {
// void save(Foo foo);
//
// void delete(String name);
// }
//
// Path: share-config/src/main/java/me/chanjar/shareconfig/service/FooRepositoryImpl.java
// public class FooRepositoryImpl implements FooRepository {
//
// private JdbcTemplate jdbcTemplate;
//
// @Override
// public void save(Foo foo) {
// jdbcTemplate.update("INSERT INTO FOO(name) VALUES (?)", foo.getName());
// }
//
// @Override
// public void delete(String name) {
// jdbcTemplate.update("DELETE FROM FOO WHERE NAME = ?", name);
// }
//
// public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
// this.jdbcTemplate = jdbcTemplate;
// }
//
// }
// Path: share-config/src/main/java/me/chanjar/shareconfig/config/FooRepositoryConfiguration.java
import me.chanjar.shareconfig.service.FooRepository;
import me.chanjar.shareconfig.service.FooRepositoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
package me.chanjar.shareconfig.config;
@Configuration
public class FooRepositoryConfiguration {
@Autowired
private JdbcTemplate jdbcTemplate;
@Bean | public FooRepository fooRepository() { |
chanjarster/spring-test-examples | share-config/src/main/java/me/chanjar/shareconfig/config/FooRepositoryConfiguration.java | // Path: share-config/src/main/java/me/chanjar/shareconfig/service/FooRepository.java
// public interface FooRepository {
// void save(Foo foo);
//
// void delete(String name);
// }
//
// Path: share-config/src/main/java/me/chanjar/shareconfig/service/FooRepositoryImpl.java
// public class FooRepositoryImpl implements FooRepository {
//
// private JdbcTemplate jdbcTemplate;
//
// @Override
// public void save(Foo foo) {
// jdbcTemplate.update("INSERT INTO FOO(name) VALUES (?)", foo.getName());
// }
//
// @Override
// public void delete(String name) {
// jdbcTemplate.update("DELETE FROM FOO WHERE NAME = ?", name);
// }
//
// public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
// this.jdbcTemplate = jdbcTemplate;
// }
//
// }
| import me.chanjar.shareconfig.service.FooRepository;
import me.chanjar.shareconfig.service.FooRepositoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate; | package me.chanjar.shareconfig.config;
@Configuration
public class FooRepositoryConfiguration {
@Autowired
private JdbcTemplate jdbcTemplate;
@Bean
public FooRepository fooRepository() { | // Path: share-config/src/main/java/me/chanjar/shareconfig/service/FooRepository.java
// public interface FooRepository {
// void save(Foo foo);
//
// void delete(String name);
// }
//
// Path: share-config/src/main/java/me/chanjar/shareconfig/service/FooRepositoryImpl.java
// public class FooRepositoryImpl implements FooRepository {
//
// private JdbcTemplate jdbcTemplate;
//
// @Override
// public void save(Foo foo) {
// jdbcTemplate.update("INSERT INTO FOO(name) VALUES (?)", foo.getName());
// }
//
// @Override
// public void delete(String name) {
// jdbcTemplate.update("DELETE FROM FOO WHERE NAME = ?", name);
// }
//
// public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
// this.jdbcTemplate = jdbcTemplate;
// }
//
// }
// Path: share-config/src/main/java/me/chanjar/shareconfig/config/FooRepositoryConfiguration.java
import me.chanjar.shareconfig.service.FooRepository;
import me.chanjar.shareconfig.service.FooRepositoryImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
package me.chanjar.shareconfig.config;
@Configuration
public class FooRepositoryConfiguration {
@Autowired
private JdbcTemplate jdbcTemplate;
@Bean
public FooRepository fooRepository() { | FooRepositoryImpl repository = new FooRepositoryImpl(); |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/mockito/MockitoTest.java | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
| import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals; | package me.chanjar.mockito;
public class MockitoTest {
@Mock | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
// Path: mock/src/test/java/me/chanjar/mockito/MockitoTest.java
import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
package me.chanjar.mockito;
public class MockitoTest {
@Mock | private Bar bar; |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/mockito/MockitoTest.java | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
| import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals; | package me.chanjar.mockito;
public class MockitoTest {
@Mock
private Bar bar;
@InjectMocks | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
// Path: mock/src/test/java/me/chanjar/mockito/MockitoTest.java
import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
package me.chanjar.mockito;
public class MockitoTest {
@Mock
private Bar bar;
@InjectMocks | private FooImpl foo; |
chanjarster/spring-test-examples | mvc/src/test/java/me/chanjar/spring2/SpringMvc_2_Test.java | // Path: mvc/src/main/java/me/chanjar/web/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
| import me.chanjar.web.Foo;
import me.chanjar.web.FooController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; | package me.chanjar.spring2;
@EnableWebMvc
@WebAppConfiguration | // Path: mvc/src/main/java/me/chanjar/web/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
// Path: mvc/src/test/java/me/chanjar/spring2/SpringMvc_2_Test.java
import me.chanjar.web.Foo;
import me.chanjar.web.FooController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
package me.chanjar.spring2;
@EnableWebMvc
@WebAppConfiguration | @ContextConfiguration(classes = { FooController.class }) |
chanjarster/spring-test-examples | mvc/src/test/java/me/chanjar/spring2/SpringMvc_2_Test.java | // Path: mvc/src/main/java/me/chanjar/web/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
| import me.chanjar.web.Foo;
import me.chanjar.web.FooController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; | package me.chanjar.spring2;
@EnableWebMvc
@WebAppConfiguration
@ContextConfiguration(classes = { FooController.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringMvc_2_Test extends AbstractTestNGSpringContextTests {
@Autowired
private WebApplicationContext wac;
@MockBean | // Path: mvc/src/main/java/me/chanjar/web/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
// Path: mvc/src/test/java/me/chanjar/spring2/SpringMvc_2_Test.java
import me.chanjar.web.Foo;
import me.chanjar.web.FooController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
package me.chanjar.spring2;
@EnableWebMvc
@WebAppConfiguration
@ContextConfiguration(classes = { FooController.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringMvc_2_Test extends AbstractTestNGSpringContextTests {
@Autowired
private WebApplicationContext wac;
@MockBean | private Foo foo; |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/springboot/ex3/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
| import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.springboot.ex3;
@SpringBootTest(classes = Config.class)
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
// Path: basic/src/test/java/me/chanjar/basic/springboot/ex3/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.springboot.ex3;
@SpringBootTest(classes = Config.class)
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | private FooService foo; |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/testconfig/ex2/Config.java | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
| import me.chanjar.annotation.testconfig.Foo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; | package me.chanjar.annotation.testconfig.ex2;
@Configuration
public class Config {
@Bean | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: annotation/src/test/java/me/chanjar/annotation/testconfig/ex2/Config.java
import me.chanjar.annotation.testconfig.Foo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
package me.chanjar.annotation.testconfig.ex2;
@Configuration
public class Config {
@Bean | public Foo foo() { |
chanjarster/spring-test-examples | aop/src/test/java/me/chanjar/aop/ex3/SpringBootAopTest.java | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
| import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.*; | package me.chanjar.aop.ex3;
@SpringBootTest(classes = { SpringBootAopTest.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringBootAopTest extends AbstractTestNGSpringContextTests {
@SpyBean | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
// Path: aop/src/test/java/me/chanjar/aop/ex3/SpringBootAopTest.java
import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.*;
package me.chanjar.aop.ex3;
@SpringBootTest(classes = { SpringBootAopTest.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringBootAopTest extends AbstractTestNGSpringContextTests {
@SpyBean | private FooAspect fooAspect; |
chanjarster/spring-test-examples | aop/src/test/java/me/chanjar/aop/ex3/SpringBootAopTest.java | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
| import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.*; | package me.chanjar.aop.ex3;
@SpringBootTest(classes = { SpringBootAopTest.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringBootAopTest extends AbstractTestNGSpringContextTests {
@SpyBean
private FooAspect fooAspect;
@Autowired | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
// Path: aop/src/test/java/me/chanjar/aop/ex3/SpringBootAopTest.java
import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.*;
package me.chanjar.aop.ex3;
@SpringBootTest(classes = { SpringBootAopTest.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringBootAopTest extends AbstractTestNGSpringContextTests {
@SpyBean
private FooAspect fooAspect;
@Autowired | private FooService fooService; |
chanjarster/spring-test-examples | aop/src/test/java/me/chanjar/aop/ex3/SpringBootAopTest.java | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
| import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.*; | package me.chanjar.aop.ex3;
@SpringBootTest(classes = { SpringBootAopTest.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringBootAopTest extends AbstractTestNGSpringContextTests {
@SpyBean
private FooAspect fooAspect;
@Autowired
private FooService fooService;
@Test
public void testFooService() {
| // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
// Path: aop/src/test/java/me/chanjar/aop/ex3/SpringBootAopTest.java
import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.*;
package me.chanjar.aop.ex3;
@SpringBootTest(classes = { SpringBootAopTest.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringBootAopTest extends AbstractTestNGSpringContextTests {
@SpyBean
private FooAspect fooAspect;
@Autowired
private FooService fooService;
@Test
public void testFooService() {
| assertNotEquals(fooService.getClass(), FooServiceImpl.class); |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/springboot1/Boot_1_Test.java | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
| import me.chanjar.common.Bar;
import me.chanjar.common.Foo;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals; | package me.chanjar.springboot1;
@SpringBootTest(classes = { FooImpl.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Boot_1_Test extends AbstractTestNGSpringContextTests {
@MockBean | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
// Path: mock/src/test/java/me/chanjar/springboot1/Boot_1_Test.java
import me.chanjar.common.Bar;
import me.chanjar.common.Foo;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
package me.chanjar.springboot1;
@SpringBootTest(classes = { FooImpl.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Boot_1_Test extends AbstractTestNGSpringContextTests {
@MockBean | private Bar bar; |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/springboot1/Boot_1_Test.java | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
| import me.chanjar.common.Bar;
import me.chanjar.common.Foo;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals; | package me.chanjar.springboot1;
@SpringBootTest(classes = { FooImpl.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Boot_1_Test extends AbstractTestNGSpringContextTests {
@MockBean
private Bar bar;
@Autowired | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
// Path: mock/src/test/java/me/chanjar/springboot1/Boot_1_Test.java
import me.chanjar.common.Bar;
import me.chanjar.common.Foo;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
package me.chanjar.springboot1;
@SpringBootTest(classes = { FooImpl.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Boot_1_Test extends AbstractTestNGSpringContextTests {
@MockBean
private Bar bar;
@Autowired | private Foo foo; |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/spring1/Spring_1_Test.java | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
| import me.chanjar.common.Bar;
import me.chanjar.common.Foo;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals; | package me.chanjar.spring1;
@ContextConfiguration(classes = FooImpl.class)
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Spring_1_Test extends AbstractTestNGSpringContextTests {
@MockBean | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
// Path: mock/src/test/java/me/chanjar/spring1/Spring_1_Test.java
import me.chanjar.common.Bar;
import me.chanjar.common.Foo;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
package me.chanjar.spring1;
@ContextConfiguration(classes = FooImpl.class)
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Spring_1_Test extends AbstractTestNGSpringContextTests {
@MockBean | private Bar bar; |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/spring1/Spring_1_Test.java | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
| import me.chanjar.common.Bar;
import me.chanjar.common.Foo;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals; | package me.chanjar.spring1;
@ContextConfiguration(classes = FooImpl.class)
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Spring_1_Test extends AbstractTestNGSpringContextTests {
@MockBean
private Bar bar;
@Autowired | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
// Path: mock/src/test/java/me/chanjar/spring1/Spring_1_Test.java
import me.chanjar.common.Bar;
import me.chanjar.common.Foo;
import me.chanjar.common.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
package me.chanjar.spring1;
@ContextConfiguration(classes = FooImpl.class)
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class Spring_1_Test extends AbstractTestNGSpringContextTests {
@MockBean
private Bar bar;
@Autowired | private Foo foo; |
chanjarster/spring-test-examples | mvc/src/test/java/me/chanjar/spring1/SpringMvc_1_Test.java | // Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return true;
// }
//
// }
| import me.chanjar.web.FooController;
import me.chanjar.web.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; | package me.chanjar.spring1;
@EnableWebMvc
@WebAppConfiguration | // Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return true;
// }
//
// }
// Path: mvc/src/test/java/me/chanjar/spring1/SpringMvc_1_Test.java
import me.chanjar.web.FooController;
import me.chanjar.web.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
package me.chanjar.spring1;
@EnableWebMvc
@WebAppConfiguration | @ContextConfiguration(classes = { FooController.class, FooImpl.class }) |
chanjarster/spring-test-examples | mvc/src/test/java/me/chanjar/spring1/SpringMvc_1_Test.java | // Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return true;
// }
//
// }
| import me.chanjar.web.FooController;
import me.chanjar.web.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; | package me.chanjar.spring1;
@EnableWebMvc
@WebAppConfiguration | // Path: mvc/src/main/java/me/chanjar/web/FooController.java
// @Controller
// public class FooController {
//
// @Autowired
// private Foo foo;
//
// @RequestMapping(path = "/foo/check-code-dup", method = RequestMethod.GET)
// public ResponseEntity<Boolean> checkCodeDuplicate(@RequestParam String code) {
//
// return new ResponseEntity<>(
// Boolean.valueOf(foo.checkCodeDuplicate(code)),
// HttpStatus.OK
// );
//
// }
//
// }
//
// Path: mvc/src/main/java/me/chanjar/web/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return true;
// }
//
// }
// Path: mvc/src/test/java/me/chanjar/spring1/SpringMvc_1_Test.java
import me.chanjar.web.FooController;
import me.chanjar.web.FooImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
package me.chanjar.spring1;
@EnableWebMvc
@WebAppConfiguration | @ContextConfiguration(classes = { FooController.class, FooImpl.class }) |
chanjarster/spring-test-examples | rdbs/src/test/java/me/chanjar/springboot1/Boot_1_IT.java | // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
| import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.springboot1;
@SpringBootTest
@SpringBootApplication(scanBasePackageClasses = FooRepository.class)
public class Boot_1_IT extends AbstractTransactionalTestNGSpringContextTests {
@Autowired
private FooRepository fooRepository;
@Autowired
private Flyway flyway;
@Test
public void testSave() {
| // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
// Path: rdbs/src/test/java/me/chanjar/springboot1/Boot_1_IT.java
import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.flywaydb.core.Flyway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.springboot1;
@SpringBootTest
@SpringBootApplication(scanBasePackageClasses = FooRepository.class)
public class Boot_1_IT extends AbstractTransactionalTestNGSpringContextTests {
@Autowired
private FooRepository fooRepository;
@Autowired
private Flyway flyway;
@Test
public void testSave() {
| Foo foo = new Foo(); |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/springboot/ex1/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
| import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.springboot.ex1;
@SpringBootTest(classes = FooServiceImpl.class)
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
// Path: basic/src/test/java/me/chanjar/basic/springboot/ex1/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.springboot.ex1;
@SpringBootTest(classes = FooServiceImpl.class)
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | private FooService foo; |
chanjarster/spring-test-examples | configuration/src/test/java/me/chanjar/configuration/ex3/FooConfiguration.java | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
| import me.chanjar.configuration.service.Foo;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; | package me.chanjar.configuration.ex3;
@Configuration
public class FooConfiguration {
@Bean
@ConditionalOnProperty(prefix = "foo", name = "create", havingValue = "true") | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
// Path: configuration/src/test/java/me/chanjar/configuration/ex3/FooConfiguration.java
import me.chanjar.configuration.service.Foo;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
package me.chanjar.configuration.ex3;
@Configuration
public class FooConfiguration {
@Bean
@ConditionalOnProperty(prefix = "foo", name = "create", havingValue = "true") | public Foo foo() { |
chanjarster/spring-test-examples | configuration/src/test/java/me/chanjar/configuration/ex4/BarConfigurationTest.java | // Path: configuration/src/main/java/me/chanjar/configuration/service/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
| import me.chanjar.configuration.service.Bar;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.configuration.ex4;
public class BarConfigurationTest {
private AnnotationConfigApplicationContext context;
@BeforeMethod
public void init() {
context = new AnnotationConfigApplicationContext();
}
@AfterMethod(alwaysRun = true)
public void reset() {
context.close();
}
@Test
public void testBarCreation() {
EnvironmentTestUtils.addEnvironment(context, "bar.name=test");
context.register(BarConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
context.refresh(); | // Path: configuration/src/main/java/me/chanjar/configuration/service/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: configuration/src/test/java/me/chanjar/configuration/ex4/BarConfigurationTest.java
import me.chanjar.configuration.service.Bar;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.configuration.ex4;
public class BarConfigurationTest {
private AnnotationConfigApplicationContext context;
@BeforeMethod
public void init() {
context = new AnnotationConfigApplicationContext();
}
@AfterMethod(alwaysRun = true)
public void reset() {
context.close();
}
@Test
public void testBarCreation() {
EnvironmentTestUtils.addEnvironment(context, "bar.name=test");
context.register(BarConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
context.refresh(); | assertEquals(context.getBean(Bar.class).getName(), "test"); |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/springboot/ex2/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
| import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.springboot.ex2;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
// Path: basic/src/test/java/me/chanjar/basic/springboot/ex2/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.springboot.ex2;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | private FooService foo; |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/springboot/ex2/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
| import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.springboot.ex2;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired
private FooService foo;
@Test
public void testPlusCount() throws Exception {
assertEquals(foo.getCount(), 0);
foo.plusCount();
assertEquals(foo.getCount(), 1);
}
@Configuration | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
// Path: basic/src/test/java/me/chanjar/basic/springboot/ex2/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.springboot.ex2;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired
private FooService foo;
@Test
public void testPlusCount() throws Exception {
assertEquals(foo.getCount(), 0);
foo.plusCount();
assertEquals(foo.getCount(), 1);
}
@Configuration | @Import(FooServiceImpl.class) |
chanjarster/spring-test-examples | rdbs/src/test/java/me/chanjar/spring1/Spring_1_IT.java | // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
| import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.spring1;
@ContextConfiguration(classes = Spring_1_IT_Configuration.class)
public class Spring_1_IT extends AbstractTestNGSpringContextTests {
@Autowired | // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
// Path: rdbs/src/test/java/me/chanjar/spring1/Spring_1_IT.java
import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.spring1;
@ContextConfiguration(classes = Spring_1_IT_Configuration.class)
public class Spring_1_IT extends AbstractTestNGSpringContextTests {
@Autowired | private FooRepository fooRepository; |
chanjarster/spring-test-examples | rdbs/src/test/java/me/chanjar/spring1/Spring_1_IT.java | // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
| import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.spring1;
@ContextConfiguration(classes = Spring_1_IT_Configuration.class)
public class Spring_1_IT extends AbstractTestNGSpringContextTests {
@Autowired
private FooRepository fooRepository;
@Autowired
private JdbcTemplate jdbcTemplate;
@Test
public void testSave() {
| // Path: rdbs/src/main/java/me/chanjar/domain/Foo.java
// public class Foo {
//
// private String name;
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
// }
//
// Path: rdbs/src/main/java/me/chanjar/domain/FooRepository.java
// public interface FooRepository {
//
// void save(Foo foo);
//
// void delete(String name);
//
// }
// Path: rdbs/src/test/java/me/chanjar/spring1/Spring_1_IT.java
import me.chanjar.domain.Foo;
import me.chanjar.domain.FooRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.spring1;
@ContextConfiguration(classes = Spring_1_IT_Configuration.class)
public class Spring_1_IT extends AbstractTestNGSpringContextTests {
@Autowired
private FooRepository fooRepository;
@Autowired
private JdbcTemplate jdbcTemplate;
@Test
public void testSave() {
| Foo foo = new Foo(); |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/jsontest/ex3/ThinJsonTest.java | // Path: annotation/src/test/java/me/chanjar/annotation/jsontest/ex1/Foo.java
// public class Foo {
//
// private String name;
//
// private int age;
//
// public Foo() {
// }
//
// public Foo(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public int getAge() {
// return age;
// }
//
// public void setAge(int age) {
// this.age = age;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Foo foo = (Foo) o;
//
// if (age != foo.age) return false;
// return name != null ? name.equals(foo.name) : foo.name == null;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + age;
// return result;
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this)
// .append("name", name)
// .append("age", age)
// .toString();
// }
// }
| import me.chanjar.annotation.jsontest.ex1.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat; | package me.chanjar.annotation.jsontest.ex3;
@JsonTest
@ContextConfiguration(classes = ThinJsonTest.class)
public class ThinJsonTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: annotation/src/test/java/me/chanjar/annotation/jsontest/ex1/Foo.java
// public class Foo {
//
// private String name;
//
// private int age;
//
// public Foo() {
// }
//
// public Foo(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public int getAge() {
// return age;
// }
//
// public void setAge(int age) {
// this.age = age;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Foo foo = (Foo) o;
//
// if (age != foo.age) return false;
// return name != null ? name.equals(foo.name) : foo.name == null;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + age;
// return result;
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this)
// .append("name", name)
// .append("age", age)
// .toString();
// }
// }
// Path: annotation/src/test/java/me/chanjar/annotation/jsontest/ex3/ThinJsonTest.java
import me.chanjar.annotation.jsontest.ex1.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
package me.chanjar.annotation.jsontest.ex3;
@JsonTest
@ContextConfiguration(classes = ThinJsonTest.class)
public class ThinJsonTest extends AbstractTestNGSpringContextTests {
@Autowired | private JacksonTester<Foo> json; |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/testconfig/ex2/TestConfigurationTest.java | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
| import me.chanjar.annotation.testconfig.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.annotation.testconfig.ex2;
@SpringBootTest(classes = { Config.class, TestConfig.class })
public class TestConfigurationTest extends AbstractTestNGSpringContextTests {
@Qualifier("foo")
@Autowired | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: annotation/src/test/java/me/chanjar/annotation/testconfig/ex2/TestConfigurationTest.java
import me.chanjar.annotation.testconfig.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.annotation.testconfig.ex2;
@SpringBootTest(classes = { Config.class, TestConfig.class })
public class TestConfigurationTest extends AbstractTestNGSpringContextTests {
@Qualifier("foo")
@Autowired | private Foo foo; |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/jsontest/ex2/FooJsonComponent.java | // Path: annotation/src/test/java/me/chanjar/annotation/jsontest/ex1/Foo.java
// public class Foo {
//
// private String name;
//
// private int age;
//
// public Foo() {
// }
//
// public Foo(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public int getAge() {
// return age;
// }
//
// public void setAge(int age) {
// this.age = age;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Foo foo = (Foo) o;
//
// if (age != foo.age) return false;
// return name != null ? name.equals(foo.name) : foo.name == null;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + age;
// return result;
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this)
// .append("name", name)
// .append("age", age)
// .toString();
// }
// }
| import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import me.chanjar.annotation.jsontest.ex1.Foo;
import org.springframework.boot.jackson.JsonComponent;
import java.io.IOException; | package me.chanjar.annotation.jsontest.ex2;
/**
* Created by qianjia on 2017/7/19.
*/
@JsonComponent
public class FooJsonComponent {
| // Path: annotation/src/test/java/me/chanjar/annotation/jsontest/ex1/Foo.java
// public class Foo {
//
// private String name;
//
// private int age;
//
// public Foo() {
// }
//
// public Foo(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public int getAge() {
// return age;
// }
//
// public void setAge(int age) {
// this.age = age;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Foo foo = (Foo) o;
//
// if (age != foo.age) return false;
// return name != null ? name.equals(foo.name) : foo.name == null;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + age;
// return result;
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this)
// .append("name", name)
// .append("age", age)
// .toString();
// }
// }
// Path: annotation/src/test/java/me/chanjar/annotation/jsontest/ex2/FooJsonComponent.java
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import me.chanjar.annotation.jsontest.ex1.Foo;
import org.springframework.boot.jackson.JsonComponent;
import java.io.IOException;
package me.chanjar.annotation.jsontest.ex2;
/**
* Created by qianjia on 2017/7/19.
*/
@JsonComponent
public class FooJsonComponent {
| public static class Serializer extends JsonSerializer<Foo> { |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/testconfig/ex1/TestConfigurationTest.java | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
| import me.chanjar.annotation.testconfig.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.annotation.testconfig.ex1;
@SpringBootTest
@SpringBootConfiguration
public class TestConfigurationTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: annotation/src/test/java/me/chanjar/annotation/testconfig/ex1/TestConfigurationTest.java
import me.chanjar.annotation.testconfig.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.annotation.testconfig.ex1;
@SpringBootTest
@SpringBootConfiguration
public class TestConfigurationTest extends AbstractTestNGSpringContextTests {
@Autowired | private Foo foo; |
chanjarster/spring-test-examples | configuration/src/test/java/me/chanjar/configuration/ex2/FooConfigurationTest.java | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
| import me.chanjar.configuration.service.Foo;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.testng.Assert.assertNotNull; | package me.chanjar.configuration.ex2;
public class FooConfigurationTest {
private AnnotationConfigApplicationContext context;
@BeforeMethod
public void init() {
context = new AnnotationConfigApplicationContext();
}
@AfterMethod(alwaysRun = true)
public void reset() {
context.close();
}
@Test(expectedExceptions = NoSuchBeanDefinitionException.class)
public void testFooCreatePropertyNull() {
context.register(FooConfiguration.class);
context.refresh(); | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
// Path: configuration/src/test/java/me/chanjar/configuration/ex2/FooConfigurationTest.java
import me.chanjar.configuration.service.Foo;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Collections;
import static org.testng.Assert.assertNotNull;
package me.chanjar.configuration.ex2;
public class FooConfigurationTest {
private AnnotationConfigApplicationContext context;
@BeforeMethod
public void init() {
context = new AnnotationConfigApplicationContext();
}
@AfterMethod(alwaysRun = true)
public void reset() {
context.close();
}
@Test(expectedExceptions = NoSuchBeanDefinitionException.class)
public void testFooCreatePropertyNull() {
context.register(FooConfiguration.class);
context.refresh(); | context.getBean(Foo.class); |
chanjarster/spring-test-examples | configuration/src/test/java/me/chanjar/configuration/ex2/FooConfiguration.java | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
| import me.chanjar.configuration.service.Foo;
import org.springframework.context.annotation.*;
import org.springframework.core.type.AnnotatedTypeMetadata; | package me.chanjar.configuration.ex2;
@Configuration
public class FooConfiguration {
@Bean
@Conditional(FooCondition.class) | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
// Path: configuration/src/test/java/me/chanjar/configuration/ex2/FooConfiguration.java
import me.chanjar.configuration.service.Foo;
import org.springframework.context.annotation.*;
import org.springframework.core.type.AnnotatedTypeMetadata;
package me.chanjar.configuration.ex2;
@Configuration
public class FooConfiguration {
@Bean
@Conditional(FooCondition.class) | public Foo foo() { |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/spring2/LooImpl.java | // Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
| import me.chanjar.common.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; | package me.chanjar.spring2;
@Component
public class LooImpl implements Loo {
| // Path: mock/src/main/java/me/chanjar/common/Foo.java
// public interface Foo {
//
// boolean checkCodeDuplicate(String code);
//
// }
// Path: mock/src/test/java/me/chanjar/spring2/LooImpl.java
import me.chanjar.common.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
package me.chanjar.spring2;
@Component
public class LooImpl implements Loo {
| private Foo foo; |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/spring/ex3/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
| import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.spring.ex3;
@ContextConfiguration(classes = Config.class)
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
// Path: basic/src/test/java/me/chanjar/basic/spring/ex3/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.spring.ex3;
@ContextConfiguration(classes = Config.class)
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | private FooService foo; |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/springboot/ex6/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
| import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.springboot.ex6;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
// Path: basic/src/test/java/me/chanjar/basic/springboot/ex6/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.springboot.ex6;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | private FooService foo; |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/no_mock/NoMockTest.java | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
| import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.testng.annotations.Test;
import java.util.Collections;
import java.util.Set;
import static org.testng.Assert.assertEquals; | package me.chanjar.no_mock;
public class NoMockTest {
@Test
public void testCheckCodeDuplicate1() throws Exception {
| // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
// Path: mock/src/test/java/me/chanjar/no_mock/NoMockTest.java
import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.testng.annotations.Test;
import java.util.Collections;
import java.util.Set;
import static org.testng.Assert.assertEquals;
package me.chanjar.no_mock;
public class NoMockTest {
@Test
public void testCheckCodeDuplicate1() throws Exception {
| FooImpl foo = new FooImpl(); |
chanjarster/spring-test-examples | mock/src/test/java/me/chanjar/no_mock/NoMockTest.java | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
| import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.testng.annotations.Test;
import java.util.Collections;
import java.util.Set;
import static org.testng.Assert.assertEquals; | package me.chanjar.no_mock;
public class NoMockTest {
@Test
public void testCheckCodeDuplicate1() throws Exception {
FooImpl foo = new FooImpl(); | // Path: mock/src/main/java/me/chanjar/common/Bar.java
// public interface Bar {
//
// Set<String> getAllCodes();
//
// }
//
// Path: mock/src/main/java/me/chanjar/common/FooImpl.java
// @Component
// public class FooImpl implements Foo {
//
// private Bar bar;
//
// @Override
// public boolean checkCodeDuplicate(String code) {
// return bar.getAllCodes().contains(code);
// }
//
// @Autowired
// public void setBar(Bar bar) {
// this.bar = bar;
// }
//
// }
// Path: mock/src/test/java/me/chanjar/no_mock/NoMockTest.java
import me.chanjar.common.Bar;
import me.chanjar.common.FooImpl;
import org.testng.annotations.Test;
import java.util.Collections;
import java.util.Set;
import static org.testng.Assert.assertEquals;
package me.chanjar.no_mock;
public class NoMockTest {
@Test
public void testCheckCodeDuplicate1() throws Exception {
FooImpl foo = new FooImpl(); | foo.setBar(new Bar() { |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/activeprofiles/ex1/ActiveProfileTest.java | // Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Config.java
// @Configuration
// public class Config {
//
// @Bean
// @Profile("dev")
// public Foo fooDev() {
// return new Foo("dev");
// }
//
// @Bean
// @Profile("product")
// public Foo fooProduct() {
// return new Foo("product");
// }
//
// @Bean
// @Profile("default")
// public Foo fooDefault() {
// return new Foo("default");
// }
//
// @Bean
// public Bar bar() {
// return new Bar("no profile");
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
| import me.chanjar.annotation.activeprofiles.Bar;
import me.chanjar.annotation.activeprofiles.Config;
import me.chanjar.annotation.activeprofiles.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.annotation.activeprofiles.ex1;
@ContextConfiguration(classes = Config.class)
public class ActiveProfileTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Config.java
// @Configuration
// public class Config {
//
// @Bean
// @Profile("dev")
// public Foo fooDev() {
// return new Foo("dev");
// }
//
// @Bean
// @Profile("product")
// public Foo fooProduct() {
// return new Foo("product");
// }
//
// @Bean
// @Profile("default")
// public Foo fooDefault() {
// return new Foo("default");
// }
//
// @Bean
// public Bar bar() {
// return new Bar("no profile");
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
// Path: annotation/src/test/java/me/chanjar/annotation/activeprofiles/ex1/ActiveProfileTest.java
import me.chanjar.annotation.activeprofiles.Bar;
import me.chanjar.annotation.activeprofiles.Config;
import me.chanjar.annotation.activeprofiles.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.annotation.activeprofiles.ex1;
@ContextConfiguration(classes = Config.class)
public class ActiveProfileTest extends AbstractTestNGSpringContextTests {
@Autowired | private Foo foo; |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/activeprofiles/ex1/ActiveProfileTest.java | // Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Config.java
// @Configuration
// public class Config {
//
// @Bean
// @Profile("dev")
// public Foo fooDev() {
// return new Foo("dev");
// }
//
// @Bean
// @Profile("product")
// public Foo fooProduct() {
// return new Foo("product");
// }
//
// @Bean
// @Profile("default")
// public Foo fooDefault() {
// return new Foo("default");
// }
//
// @Bean
// public Bar bar() {
// return new Bar("no profile");
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
| import me.chanjar.annotation.activeprofiles.Bar;
import me.chanjar.annotation.activeprofiles.Config;
import me.chanjar.annotation.activeprofiles.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.annotation.activeprofiles.ex1;
@ContextConfiguration(classes = Config.class)
public class ActiveProfileTest extends AbstractTestNGSpringContextTests {
@Autowired
private Foo foo;
@Autowired | // Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Bar.java
// public class Bar {
//
// private final String name;
//
// public Bar(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Config.java
// @Configuration
// public class Config {
//
// @Bean
// @Profile("dev")
// public Foo fooDev() {
// return new Foo("dev");
// }
//
// @Bean
// @Profile("product")
// public Foo fooProduct() {
// return new Foo("product");
// }
//
// @Bean
// @Profile("default")
// public Foo fooDefault() {
// return new Foo("default");
// }
//
// @Bean
// public Bar bar() {
// return new Bar("no profile");
// }
//
// }
//
// Path: annotation/src/main/java/me/chanjar/annotation/activeprofiles/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
//
// }
// Path: annotation/src/test/java/me/chanjar/annotation/activeprofiles/ex1/ActiveProfileTest.java
import me.chanjar.annotation.activeprofiles.Bar;
import me.chanjar.annotation.activeprofiles.Config;
import me.chanjar.annotation.activeprofiles.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.annotation.activeprofiles.ex1;
@ContextConfiguration(classes = Config.class)
public class ActiveProfileTest extends AbstractTestNGSpringContextTests {
@Autowired
private Foo foo;
@Autowired | private Bar bar; |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/springboot/ex5/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
| import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.springboot.ex5;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
// Path: basic/src/test/java/me/chanjar/basic/springboot/ex5/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.springboot.ex5;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | private FooService foo; |
chanjarster/spring-test-examples | aop/src/test/java/me/chanjar/aop/ex1/SpringAop_1_Test.java | // Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
| import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.testng.Assert.*; | package me.chanjar.aop.ex1;
@ContextConfiguration(classes = { SpringAop_1_Test.class, AopConfig.class })
public class SpringAop_1_Test extends AbstractTestNGSpringContextTests {
@Autowired | // Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
// Path: aop/src/test/java/me/chanjar/aop/ex1/SpringAop_1_Test.java
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
package me.chanjar.aop.ex1;
@ContextConfiguration(classes = { SpringAop_1_Test.class, AopConfig.class })
public class SpringAop_1_Test extends AbstractTestNGSpringContextTests {
@Autowired | private FooService fooService; |
chanjarster/spring-test-examples | aop/src/test/java/me/chanjar/aop/ex1/SpringAop_1_Test.java | // Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
| import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.testng.Assert.*; | package me.chanjar.aop.ex1;
@ContextConfiguration(classes = { SpringAop_1_Test.class, AopConfig.class })
public class SpringAop_1_Test extends AbstractTestNGSpringContextTests {
@Autowired
private FooService fooService;
@Test
public void testFooService() {
| // Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
// Path: aop/src/test/java/me/chanjar/aop/ex1/SpringAop_1_Test.java
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
package me.chanjar.aop.ex1;
@ContextConfiguration(classes = { SpringAop_1_Test.class, AopConfig.class })
public class SpringAop_1_Test extends AbstractTestNGSpringContextTests {
@Autowired
private FooService fooService;
@Test
public void testFooService() {
| assertNotEquals(fooService.getClass(), FooServiceImpl.class); |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/jsontest/ex2/JsonComponentJacksonTest.java | // Path: annotation/src/test/java/me/chanjar/annotation/jsontest/ex1/Foo.java
// public class Foo {
//
// private String name;
//
// private int age;
//
// public Foo() {
// }
//
// public Foo(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public int getAge() {
// return age;
// }
//
// public void setAge(int age) {
// this.age = age;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Foo foo = (Foo) o;
//
// if (age != foo.age) return false;
// return name != null ? name.equals(foo.name) : foo.name == null;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + age;
// return result;
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this)
// .append("name", name)
// .append("age", age)
// .toString();
// }
// }
| import me.chanjar.annotation.jsontest.ex1.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat; | package me.chanjar.annotation.jsontest.ex2;
@SpringBootTest(classes = { JsonComponentJacksonTest.class, FooJsonComponent.class })
@JsonTest
public class JsonComponentJacksonTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: annotation/src/test/java/me/chanjar/annotation/jsontest/ex1/Foo.java
// public class Foo {
//
// private String name;
//
// private int age;
//
// public Foo() {
// }
//
// public Foo(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public int getAge() {
// return age;
// }
//
// public void setAge(int age) {
// this.age = age;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
//
// Foo foo = (Foo) o;
//
// if (age != foo.age) return false;
// return name != null ? name.equals(foo.name) : foo.name == null;
// }
//
// @Override
// public int hashCode() {
// int result = name != null ? name.hashCode() : 0;
// result = 31 * result + age;
// return result;
// }
//
// @Override
// public String toString() {
// return new ToStringBuilder(this)
// .append("name", name)
// .append("age", age)
// .toString();
// }
// }
// Path: annotation/src/test/java/me/chanjar/annotation/jsontest/ex2/JsonComponentJacksonTest.java
import me.chanjar.annotation.jsontest.ex1.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.JsonTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.assertj.core.api.Assertions.assertThat;
package me.chanjar.annotation.jsontest.ex2;
@SpringBootTest(classes = { JsonComponentJacksonTest.class, FooJsonComponent.class })
@JsonTest
public class JsonComponentJacksonTest extends AbstractTestNGSpringContextTests {
@Autowired | private JacksonTester<Foo> json; |
chanjarster/spring-test-examples | aop/src/test/java/me/chanjar/aop/ex2/SpringAop_2_Test.java | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
| import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue; | package me.chanjar.aop.ex2;
@ContextConfiguration(classes = { SpringAop_2_Test.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringAop_2_Test extends AbstractTestNGSpringContextTests {
@SpyBean | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
// Path: aop/src/test/java/me/chanjar/aop/ex2/SpringAop_2_Test.java
import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
package me.chanjar.aop.ex2;
@ContextConfiguration(classes = { SpringAop_2_Test.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringAop_2_Test extends AbstractTestNGSpringContextTests {
@SpyBean | private FooAspect fooAspect; |
chanjarster/spring-test-examples | aop/src/test/java/me/chanjar/aop/ex2/SpringAop_2_Test.java | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
| import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue; | package me.chanjar.aop.ex2;
@ContextConfiguration(classes = { SpringAop_2_Test.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringAop_2_Test extends AbstractTestNGSpringContextTests {
@SpyBean
private FooAspect fooAspect;
@Autowired | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
// Path: aop/src/test/java/me/chanjar/aop/ex2/SpringAop_2_Test.java
import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
package me.chanjar.aop.ex2;
@ContextConfiguration(classes = { SpringAop_2_Test.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringAop_2_Test extends AbstractTestNGSpringContextTests {
@SpyBean
private FooAspect fooAspect;
@Autowired | private FooService fooService; |
chanjarster/spring-test-examples | aop/src/test/java/me/chanjar/aop/ex2/SpringAop_2_Test.java | // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
| import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue; | package me.chanjar.aop.ex2;
@ContextConfiguration(classes = { SpringAop_2_Test.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringAop_2_Test extends AbstractTestNGSpringContextTests {
@SpyBean
private FooAspect fooAspect;
@Autowired
private FooService fooService;
@Test
public void testFooService() {
| // Path: aop/src/main/java/me/chanjar/aop/aspect/FooAspect.java
// @Component
// @Aspect
// public class FooAspect {
//
// @Pointcut("execution(* me.chanjar.aop.service.FooServiceImpl.incrementAndGet())")
// public void pointcut() {
// }
//
// @Around("pointcut()")
// public int changeIncrementAndGet(ProceedingJoinPoint pjp) {
// return 0;
// }
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/config/AopConfig.java
// @Configuration
// @EnableAspectJAutoProxy(proxyTargetClass = true)
// @ComponentScan("me.chanjar.aop")
// public class AopConfig {
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooService.java
// public interface FooService {
//
// int incrementAndGet();
//
// }
//
// Path: aop/src/main/java/me/chanjar/aop/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count;
//
// @Override
// public int incrementAndGet() {
// count++;
// return count;
// }
//
// }
// Path: aop/src/test/java/me/chanjar/aop/ex2/SpringAop_2_Test.java
import me.chanjar.aop.aspect.FooAspect;
import me.chanjar.aop.config.AopConfig;
import me.chanjar.aop.service.FooService;
import me.chanjar.aop.service.FooServiceImpl;
import org.springframework.aop.framework.AopProxyUtils;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.springframework.test.util.AopTestUtils;
import org.testng.annotations.Test;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
package me.chanjar.aop.ex2;
@ContextConfiguration(classes = { SpringAop_2_Test.class, AopConfig.class })
@TestExecutionListeners(listeners = MockitoTestExecutionListener.class)
public class SpringAop_2_Test extends AbstractTestNGSpringContextTests {
@SpyBean
private FooAspect fooAspect;
@Autowired
private FooService fooService;
@Test
public void testFooService() {
| assertNotEquals(fooService.getClass(), FooServiceImpl.class); |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/testconfig/ex2/TestConfig.java | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
| import me.chanjar.annotation.testconfig.Foo;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean; | package me.chanjar.annotation.testconfig.ex2;
@TestConfiguration
public class TestConfig {
@Bean | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: annotation/src/test/java/me/chanjar/annotation/testconfig/ex2/TestConfig.java
import me.chanjar.annotation.testconfig.Foo;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
package me.chanjar.annotation.testconfig.ex2;
@TestConfiguration
public class TestConfig {
@Bean | public Foo foo() { |
chanjarster/spring-test-examples | annotation/src/test/java/me/chanjar/annotation/testconfig/ex3/TestConfig.java | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
| import me.chanjar.annotation.testconfig.Foo;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean; | package me.chanjar.annotation.testconfig.ex3;
@TestConfiguration
public class TestConfig {
@Bean | // Path: annotation/src/main/java/me/chanjar/annotation/testconfig/Foo.java
// public class Foo {
//
// private final String name;
//
// public Foo(String name) {
// this.name = name;
// }
//
// public String getName() {
// return name;
// }
// }
// Path: annotation/src/test/java/me/chanjar/annotation/testconfig/ex3/TestConfig.java
import me.chanjar.annotation.testconfig.Foo;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
package me.chanjar.annotation.testconfig.ex3;
@TestConfiguration
public class TestConfig {
@Bean | public Foo foo() { |
chanjarster/spring-test-examples | configuration/src/test/java/me/chanjar/configuration/ex1/FooConfiguration.java | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
| import me.chanjar.configuration.service.Foo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; | package me.chanjar.configuration.ex1;
@Configuration
public class FooConfiguration {
@Bean | // Path: configuration/src/main/java/me/chanjar/configuration/service/Foo.java
// public class Foo {
// }
// Path: configuration/src/test/java/me/chanjar/configuration/ex1/FooConfiguration.java
import me.chanjar.configuration.service.Foo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
package me.chanjar.configuration.ex1;
@Configuration
public class FooConfiguration {
@Bean | public Foo foo() { |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/spring/ex1/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
| import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.spring.ex1;
@ContextConfiguration(classes = FooServiceImpl.class)
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
// Path: basic/src/test/java/me/chanjar/basic/spring/ex1/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.spring.ex1;
@ContextConfiguration(classes = FooServiceImpl.class)
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | private FooService foo; |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/spring/ex2/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
| import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.spring.ex2;
@ContextConfiguration
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
// Path: basic/src/test/java/me/chanjar/basic/spring/ex2/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.spring.ex2;
@ContextConfiguration
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | private FooService foo; |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/spring/ex2/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
| import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.spring.ex2;
@ContextConfiguration
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired
private FooService foo;
@Test
public void testPlusCount() throws Exception {
assertEquals(foo.getCount(), 0);
foo.plusCount();
assertEquals(foo.getCount(), 1);
}
@Configuration | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
//
// Path: basic/src/main/java/me/chanjar/basic/service/FooServiceImpl.java
// @Component
// public class FooServiceImpl implements FooService {
//
// private int count = 0;
//
// @Override
// public void plusCount() {
// this.count++;
// }
//
// @Override
// public int getCount() {
// return count;
// }
//
// }
// Path: basic/src/test/java/me/chanjar/basic/spring/ex2/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import me.chanjar.basic.service.FooServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.spring.ex2;
@ContextConfiguration
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired
private FooService foo;
@Test
public void testPlusCount() throws Exception {
assertEquals(foo.getCount(), 0);
foo.plusCount();
assertEquals(foo.getCount(), 1);
}
@Configuration | @Import(FooServiceImpl.class) |
chanjarster/spring-test-examples | basic/src/test/java/me/chanjar/basic/springboot/ex4/FooServiceImplTest.java | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
| import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals; | package me.chanjar.basic.springboot.ex4;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | // Path: basic/src/main/java/me/chanjar/basic/service/FooService.java
// public interface FooService {
//
// void plusCount();
//
// int getCount();
//
// }
// Path: basic/src/test/java/me/chanjar/basic/springboot/ex4/FooServiceImplTest.java
import me.chanjar.basic.service.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
package me.chanjar.basic.springboot.ex4;
@SpringBootTest
public class FooServiceImplTest extends AbstractTestNGSpringContextTests {
@Autowired | private FooService foo; |
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/Explodable.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
| import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.game.feature.FeatureGet;
import com.b3dgs.lionengine.game.feature.FeatureInterface;
import com.b3dgs.lionengine.game.feature.FeatureModel;
import com.b3dgs.lionengine.game.feature.Identifiable;
import com.b3dgs.lionengine.game.feature.Routine;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Spawner;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.constant.Folder;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.object.feature;
/**
* Represents something that can explode.
*/
@FeatureInterface
public class Explodable extends FeatureModel implements Routine
{
private final Spawner spawner = services.get(Spawner.class);
@FeatureGet private Identifiable identifiable;
@FeatureGet private Transformable transformable;
@FeatureGet private Pathfindable pathfindable;
@FeatureGet private EntityStats stats;
/**
* Create feature.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Explodable(Services services, Setup setup)
{
super(services, setup);
}
@Override
public void update(double extrp)
{
if (stats.getHealthPercent() == 0)
{
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/Explodable.java
import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.game.feature.FeatureGet;
import com.b3dgs.lionengine.game.feature.FeatureInterface;
import com.b3dgs.lionengine.game.feature.FeatureModel;
import com.b3dgs.lionengine.game.feature.Identifiable;
import com.b3dgs.lionengine.game.feature.Routine;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Spawner;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.constant.Folder;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.object.feature;
/**
* Represents something that can explode.
*/
@FeatureInterface
public class Explodable extends FeatureModel implements Routine
{
private final Spawner spawner = services.get(Spawner.class);
@FeatureGet private Identifiable identifiable;
@FeatureGet private Transformable transformable;
@FeatureGet private Pathfindable pathfindable;
@FeatureGet private EntityStats stats;
/**
* Create feature.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Explodable(Services services, Setup setup)
{
super(services, setup);
}
@Override
public void update(double extrp)
{
if (stats.getHealthPercent() == 0)
{
| spawner.spawn(Medias.create(Folder.EFFECTS, "explode.xml"), transformable)
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/action/Extract.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/RightClickExtract.java
// @FeatureInterface
// public class RightClickExtract extends FeatureModel implements RightClickHandler
// {
// private final Cursor cursor = services.get(Cursor.class);
// private final Handler handler = services.get(Handler.class);
// private final MapTile map = services.get(MapTile.class);
// private final MapTilePath mapPath = map.getFeature(MapTilePath.class);
// private final Player player = services.get(Player.class);
//
// @FeatureGet private Extractor extractor;
// @FeatureGet private Pathfindable pathfindable;
// @FeatureGet private EntityModel model;
// @FeatureGet private EntitySfx sfx;
//
// /**
// * Create action.
// *
// * @param services The services reference.
// * @param setup The setup reference.
// */
// public RightClickExtract(Services services, Setup setup)
// {
// super(services, setup);
// }
//
// private void extractGoldmine(int tx, int ty)
// {
// for (final Integer id : mapPath.getObjectsId(tx, ty))
// {
// final Featurable featurable = handler.get(id);
// if (featurable.hasFeature(Extractable.class))
// {
// final Extractable extractable = featurable.getFeature(Extractable.class);
// extractor.setResource(extractable);
// pathfindable.setDestination(extractable);
// extractor.startExtraction();
// }
// }
// }
//
// @Override
// public void execute()
// {
// if (player.owns(this))
// {
// final int tx = map.getInTileX(cursor);
// final int ty = map.getInTileY(cursor);
//
// pathfindable.setDestination(tx, ty);
//
// if (model.getCarryResource() == null)
// {
// extractor.stopExtraction();
// final Tile tree = map.getTile(tx, ty);
// if (Constant.CATEGORY_TREE.equals(mapPath.getCategory(tree)))
// {
// extractor.setResource(Constant.RESOURCE_WOOD, tree);
// extractor.startExtraction();
// }
// else
// {
// extractGoldmine(tx, ty);
// }
// }
// sfx.onOrdered();
// }
// }
// }
| import java.util.List;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.collidable.selector.Selectable;
import com.b3dgs.warcraft.object.feature.RightClickExtract;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.action;
/**
* Extract action.
*/
public class Extract extends ActionModel
{
/**
* Create action.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Extract(Services services, Setup setup)
{
super(services, setup);
}
@Override
protected boolean assign()
{
final List<Selectable> selection = selector.getSelection();
final int n = selection.size();
for (int i = 0; i < n; i++)
{
final Selectable selectable = selection.get(i);
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/RightClickExtract.java
// @FeatureInterface
// public class RightClickExtract extends FeatureModel implements RightClickHandler
// {
// private final Cursor cursor = services.get(Cursor.class);
// private final Handler handler = services.get(Handler.class);
// private final MapTile map = services.get(MapTile.class);
// private final MapTilePath mapPath = map.getFeature(MapTilePath.class);
// private final Player player = services.get(Player.class);
//
// @FeatureGet private Extractor extractor;
// @FeatureGet private Pathfindable pathfindable;
// @FeatureGet private EntityModel model;
// @FeatureGet private EntitySfx sfx;
//
// /**
// * Create action.
// *
// * @param services The services reference.
// * @param setup The setup reference.
// */
// public RightClickExtract(Services services, Setup setup)
// {
// super(services, setup);
// }
//
// private void extractGoldmine(int tx, int ty)
// {
// for (final Integer id : mapPath.getObjectsId(tx, ty))
// {
// final Featurable featurable = handler.get(id);
// if (featurable.hasFeature(Extractable.class))
// {
// final Extractable extractable = featurable.getFeature(Extractable.class);
// extractor.setResource(extractable);
// pathfindable.setDestination(extractable);
// extractor.startExtraction();
// }
// }
// }
//
// @Override
// public void execute()
// {
// if (player.owns(this))
// {
// final int tx = map.getInTileX(cursor);
// final int ty = map.getInTileY(cursor);
//
// pathfindable.setDestination(tx, ty);
//
// if (model.getCarryResource() == null)
// {
// extractor.stopExtraction();
// final Tile tree = map.getTile(tx, ty);
// if (Constant.CATEGORY_TREE.equals(mapPath.getCategory(tree)))
// {
// extractor.setResource(Constant.RESOURCE_WOOD, tree);
// extractor.startExtraction();
// }
// else
// {
// extractGoldmine(tx, ty);
// }
// }
// sfx.onOrdered();
// }
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/action/Extract.java
import java.util.List;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.collidable.selector.Selectable;
import com.b3dgs.warcraft.object.feature.RightClickExtract;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.action;
/**
* Extract action.
*/
public class Extract extends ActionModel
{
/**
* Create action.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Extract(Services services, Setup setup)
{
super(services, setup);
}
@Override
protected boolean assign()
{
final List<Selectable> selection = selector.getSelection();
final int n = selection.size();
for (int i = 0; i < n; i++)
{
final Selectable selectable = selection.get(i);
| selectable.getFeature(RightClickExtract.class).execute();
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/action/Stop.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/EntitySfx.java
// @FeatureInterface
// public class EntitySfx extends FeatureModel
// {
// private static final String ATT_STARTED = "started";
// private static final String ATT_PRODUCED = "produced";
// private static final String ATT_SELECTED = "selected";
// private static final String ATT_ORDERED = "ordered";
// private static final String ATT_ATTACKED = "attacked";
//
// private final List<Sfx> started;
// private final List<Sfx> produced;
// private final List<Sfx> selected;
// private final List<Sfx> ordered;
// private final List<Sfx> attacked;
// private final List<Sfx> dead;
//
// private final Viewer viewer = services.get(Viewer.class);
// private final Player player = services.get(Player.class);
// private final FogOfWar fogOfWar = services.get(FogOfWar.class);
//
// @FeatureGet private Transformable transformable;
// @FeatureGet private Pathfindable pathfindable;
//
// /**
// * Create producing.
// *
// * @param services The services reference.
// * @param setup The setup reference.
// * @throws LionEngineException If invalid configuration.
// */
// public EntitySfx(Services services, Setup setup)
// {
// super(services, setup);
//
// started = Sfx.load(setup, ATT_STARTED);
// produced = Sfx.load(setup, ATT_PRODUCED);
// selected = Sfx.load(setup, ATT_SELECTED);
// ordered = Sfx.load(setup, ATT_ORDERED);
// attacked = Sfx.load(setup, ATT_ATTACKED);
// dead = Sfx.load(setup, Sfx.ATT_DEAD);
// }
//
// /**
// * Called on production started.
// */
// public void onStarted()
// {
// if (isVisible())
// {
// Sfx.playRandom(started);
// }
// }
//
// /**
// * Called on production ended.
// */
// public void onProduced()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(produced);
// }
// }
//
// /**
// * Called on selected.
// */
// public void onSelected()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(selected);
// }
// }
//
// /**
// * Called on ordered.
// */
// public void onOrdered()
// {
// if (isVisible())
// {
// Sfx.playRandom(ordered);
// }
// }
//
// /**
// * Called on attacked.
// */
// public void onAttacked()
// {
// if (isVisible())
// {
// Sfx.playRandom(attacked);
// }
// }
//
// /**
// * Called on dead.
// */
// public void onDead()
// {
// if (isVisible())
// {
// Sfx.playRandom(dead);
// }
// }
//
// /**
// * Check if visible on camera and not fogged.
// *
// * @return <code>true</code> if truly visible, <code>false</code> else.
// */
// private boolean isVisible()
// {
// return viewer.isViewable(transformable, 0, 0) && fogOfWar.isVisible(pathfindable);
// }
// }
| import java.util.List;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.attackable.Attacker;
import com.b3dgs.lionengine.game.feature.collidable.selector.Selectable;
import com.b3dgs.lionengine.game.feature.tile.map.extractable.Extractor;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.feature.EntitySfx;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.action;
/**
* Stop action.
*/
public class Stop extends ActionModel
{
/**
* Create action.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Stop(Services services, Setup setup)
{
super(services, setup);
actionable.setAction(() ->
{
final List<Selectable> selection = selector.getSelection();
final int n = selection.size();
for (int i = 0; i < n; i++)
{
final Selectable selectable = selection.get(i);
selectable.getFeature(Pathfindable.class).stopMoves();
selectable.getFeature(Attacker.class).stopAttack();
selectable.getFeature(Extractor.class).stopExtraction();
if (i == 0)
{
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/EntitySfx.java
// @FeatureInterface
// public class EntitySfx extends FeatureModel
// {
// private static final String ATT_STARTED = "started";
// private static final String ATT_PRODUCED = "produced";
// private static final String ATT_SELECTED = "selected";
// private static final String ATT_ORDERED = "ordered";
// private static final String ATT_ATTACKED = "attacked";
//
// private final List<Sfx> started;
// private final List<Sfx> produced;
// private final List<Sfx> selected;
// private final List<Sfx> ordered;
// private final List<Sfx> attacked;
// private final List<Sfx> dead;
//
// private final Viewer viewer = services.get(Viewer.class);
// private final Player player = services.get(Player.class);
// private final FogOfWar fogOfWar = services.get(FogOfWar.class);
//
// @FeatureGet private Transformable transformable;
// @FeatureGet private Pathfindable pathfindable;
//
// /**
// * Create producing.
// *
// * @param services The services reference.
// * @param setup The setup reference.
// * @throws LionEngineException If invalid configuration.
// */
// public EntitySfx(Services services, Setup setup)
// {
// super(services, setup);
//
// started = Sfx.load(setup, ATT_STARTED);
// produced = Sfx.load(setup, ATT_PRODUCED);
// selected = Sfx.load(setup, ATT_SELECTED);
// ordered = Sfx.load(setup, ATT_ORDERED);
// attacked = Sfx.load(setup, ATT_ATTACKED);
// dead = Sfx.load(setup, Sfx.ATT_DEAD);
// }
//
// /**
// * Called on production started.
// */
// public void onStarted()
// {
// if (isVisible())
// {
// Sfx.playRandom(started);
// }
// }
//
// /**
// * Called on production ended.
// */
// public void onProduced()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(produced);
// }
// }
//
// /**
// * Called on selected.
// */
// public void onSelected()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(selected);
// }
// }
//
// /**
// * Called on ordered.
// */
// public void onOrdered()
// {
// if (isVisible())
// {
// Sfx.playRandom(ordered);
// }
// }
//
// /**
// * Called on attacked.
// */
// public void onAttacked()
// {
// if (isVisible())
// {
// Sfx.playRandom(attacked);
// }
// }
//
// /**
// * Called on dead.
// */
// public void onDead()
// {
// if (isVisible())
// {
// Sfx.playRandom(dead);
// }
// }
//
// /**
// * Check if visible on camera and not fogged.
// *
// * @return <code>true</code> if truly visible, <code>false</code> else.
// */
// private boolean isVisible()
// {
// return viewer.isViewable(transformable, 0, 0) && fogOfWar.isVisible(pathfindable);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/action/Stop.java
import java.util.List;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.attackable.Attacker;
import com.b3dgs.lionengine.game.feature.collidable.selector.Selectable;
import com.b3dgs.lionengine.game.feature.tile.map.extractable.Extractor;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.feature.EntitySfx;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.action;
/**
* Stop action.
*/
public class Stop extends ActionModel
{
/**
* Create action.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Stop(Services services, Setup setup)
{
super(services, setup);
actionable.setAction(() ->
{
final List<Selectable> selection = selector.getSelection();
final int n = selection.size();
for (int i = 0; i < n; i++)
{
final Selectable selectable = selection.get(i);
selectable.getFeature(Pathfindable.class).stopMoves();
selectable.getFeature(Attacker.class).stopAttack();
selectable.getFeature(Extractor.class).stopExtraction();
if (i == 0)
{
| selectable.getFeature(EntitySfx.class).onOrdered();
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/action/Move.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/EntitySfx.java
// @FeatureInterface
// public class EntitySfx extends FeatureModel
// {
// private static final String ATT_STARTED = "started";
// private static final String ATT_PRODUCED = "produced";
// private static final String ATT_SELECTED = "selected";
// private static final String ATT_ORDERED = "ordered";
// private static final String ATT_ATTACKED = "attacked";
//
// private final List<Sfx> started;
// private final List<Sfx> produced;
// private final List<Sfx> selected;
// private final List<Sfx> ordered;
// private final List<Sfx> attacked;
// private final List<Sfx> dead;
//
// private final Viewer viewer = services.get(Viewer.class);
// private final Player player = services.get(Player.class);
// private final FogOfWar fogOfWar = services.get(FogOfWar.class);
//
// @FeatureGet private Transformable transformable;
// @FeatureGet private Pathfindable pathfindable;
//
// /**
// * Create producing.
// *
// * @param services The services reference.
// * @param setup The setup reference.
// * @throws LionEngineException If invalid configuration.
// */
// public EntitySfx(Services services, Setup setup)
// {
// super(services, setup);
//
// started = Sfx.load(setup, ATT_STARTED);
// produced = Sfx.load(setup, ATT_PRODUCED);
// selected = Sfx.load(setup, ATT_SELECTED);
// ordered = Sfx.load(setup, ATT_ORDERED);
// attacked = Sfx.load(setup, ATT_ATTACKED);
// dead = Sfx.load(setup, Sfx.ATT_DEAD);
// }
//
// /**
// * Called on production started.
// */
// public void onStarted()
// {
// if (isVisible())
// {
// Sfx.playRandom(started);
// }
// }
//
// /**
// * Called on production ended.
// */
// public void onProduced()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(produced);
// }
// }
//
// /**
// * Called on selected.
// */
// public void onSelected()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(selected);
// }
// }
//
// /**
// * Called on ordered.
// */
// public void onOrdered()
// {
// if (isVisible())
// {
// Sfx.playRandom(ordered);
// }
// }
//
// /**
// * Called on attacked.
// */
// public void onAttacked()
// {
// if (isVisible())
// {
// Sfx.playRandom(attacked);
// }
// }
//
// /**
// * Called on dead.
// */
// public void onDead()
// {
// if (isVisible())
// {
// Sfx.playRandom(dead);
// }
// }
//
// /**
// * Check if visible on camera and not fogged.
// *
// * @return <code>true</code> if truly visible, <code>false</code> else.
// */
// private boolean isVisible()
// {
// return viewer.isViewable(transformable, 0, 0) && fogOfWar.isVisible(pathfindable);
// }
// }
| import java.util.List;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.attackable.Attacker;
import com.b3dgs.lionengine.game.feature.collidable.selector.Selectable;
import com.b3dgs.lionengine.game.feature.tile.map.extractable.Extractor;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.feature.EntitySfx;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.action;
/**
* Move action.
*/
public class Move extends ActionModel
{
/**
* Create action.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Move(Services services, Setup setup)
{
super(services, setup);
}
@Override
protected boolean assign()
{
final List<Selectable> selection = selector.getSelection();
final int n = selection.size();
for (int i = 0; i < n; i++)
{
final Selectable selectable = selection.get(i);
selectable.getFeature(Attacker.class).stopAttack();
selectable.getFeature(Extractor.class).stopExtraction();
selectable.getFeature(Pathfindable.class).setDestination(cursor);
if (i == 0)
{
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/EntitySfx.java
// @FeatureInterface
// public class EntitySfx extends FeatureModel
// {
// private static final String ATT_STARTED = "started";
// private static final String ATT_PRODUCED = "produced";
// private static final String ATT_SELECTED = "selected";
// private static final String ATT_ORDERED = "ordered";
// private static final String ATT_ATTACKED = "attacked";
//
// private final List<Sfx> started;
// private final List<Sfx> produced;
// private final List<Sfx> selected;
// private final List<Sfx> ordered;
// private final List<Sfx> attacked;
// private final List<Sfx> dead;
//
// private final Viewer viewer = services.get(Viewer.class);
// private final Player player = services.get(Player.class);
// private final FogOfWar fogOfWar = services.get(FogOfWar.class);
//
// @FeatureGet private Transformable transformable;
// @FeatureGet private Pathfindable pathfindable;
//
// /**
// * Create producing.
// *
// * @param services The services reference.
// * @param setup The setup reference.
// * @throws LionEngineException If invalid configuration.
// */
// public EntitySfx(Services services, Setup setup)
// {
// super(services, setup);
//
// started = Sfx.load(setup, ATT_STARTED);
// produced = Sfx.load(setup, ATT_PRODUCED);
// selected = Sfx.load(setup, ATT_SELECTED);
// ordered = Sfx.load(setup, ATT_ORDERED);
// attacked = Sfx.load(setup, ATT_ATTACKED);
// dead = Sfx.load(setup, Sfx.ATT_DEAD);
// }
//
// /**
// * Called on production started.
// */
// public void onStarted()
// {
// if (isVisible())
// {
// Sfx.playRandom(started);
// }
// }
//
// /**
// * Called on production ended.
// */
// public void onProduced()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(produced);
// }
// }
//
// /**
// * Called on selected.
// */
// public void onSelected()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(selected);
// }
// }
//
// /**
// * Called on ordered.
// */
// public void onOrdered()
// {
// if (isVisible())
// {
// Sfx.playRandom(ordered);
// }
// }
//
// /**
// * Called on attacked.
// */
// public void onAttacked()
// {
// if (isVisible())
// {
// Sfx.playRandom(attacked);
// }
// }
//
// /**
// * Called on dead.
// */
// public void onDead()
// {
// if (isVisible())
// {
// Sfx.playRandom(dead);
// }
// }
//
// /**
// * Check if visible on camera and not fogged.
// *
// * @return <code>true</code> if truly visible, <code>false</code> else.
// */
// private boolean isVisible()
// {
// return viewer.isViewable(transformable, 0, 0) && fogOfWar.isVisible(pathfindable);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/action/Move.java
import java.util.List;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.attackable.Attacker;
import com.b3dgs.lionengine.game.feature.collidable.selector.Selectable;
import com.b3dgs.lionengine.game.feature.tile.map.extractable.Extractor;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.feature.EntitySfx;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.action;
/**
* Move action.
*/
public class Move extends ActionModel
{
/**
* Create action.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Move(Services services, Setup setup)
{
super(services, setup);
}
@Override
protected boolean assign()
{
final List<Selectable> selection = selector.getSelection();
final int n = selection.size();
for (int i = 0; i < n; i++)
{
final Selectable selectable = selection.get(i);
selectable.getFeature(Attacker.class).stopAttack();
selectable.getFeature(Extractor.class).stopExtraction();
selectable.getFeature(Pathfindable.class).setDestination(cursor);
if (i == 0)
{
| selection.get(0).getFeature(EntitySfx.class).onOrdered();
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/Race.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
| import java.util.Locale;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.game.feature.Factory;
import com.b3dgs.warcraft.constant.Folder;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of available races.
*/
public enum Race
{
/** Orc race. */
ORC,
/** Human race. */
HUMAN,
/** Neutral. */
NEUTRAL;
/** The race folder. */
private final String folder = name().toLowerCase(Locale.ENGLISH);
/**
* Get a unit based on its race
*
* @param unit The unit reference.
* @return The unit media.
*/
public Media get(Unit unit)
{
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/Race.java
import java.util.Locale;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.game.feature.Factory;
import com.b3dgs.warcraft.constant.Folder;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of available races.
*/
public enum Race
{
/** Orc race. */
ORC,
/** Human race. */
HUMAN,
/** Neutral. */
NEUTRAL;
/** The race folder. */
private final String folder = name().toLowerCase(Locale.ENGLISH);
/**
* Get a unit based on its race
*
* @param unit The unit reference.
* @return The unit media.
*/
public Media get(Unit unit)
{
| return Medias.create(Folder.ENTITIES, folder, unit.get() + Factory.FILE_DATA_DOT_EXTENSION);
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/Level.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Extension.java
// public final class Extension
// {
// /** Image file extension (with dot). */
// public static final String IMAGE = ".png";
// /** Levels file extension (with dot). */
// public static final String LEVEL = ".wrl";
// /** Sounds file extension (with dot). */
// public static final String SFX = ".wav";
// /** Musics file extension (with dot). */
// public static final String MUSIC = ".xmi";
//
// /**
// * Private constructor.
// */
// private Extension()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
| import com.b3dgs.lionengine.Check;
import com.b3dgs.lionengine.LionEngineException;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.warcraft.constant.Extension;
import com.b3dgs.warcraft.constant.Folder;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of levels with their file.
*/
public enum Level
{
/** Forest level. */
FOREST(WorldType.FOREST, "forest"),
/** Swamp level. */
SWAMP(WorldType.SWAMP, "swamp");
/** Level file. */
private final Media level;
/** Level rip image. */
private final Media rip;
/**
* Create the level.
*
* @param world The level world (must not be <code>null</code>).
* @param level The level file name (must not be <code>null</code>).
* @throws LionEngineException If invalid argument.
*/
Level(WorldType world, String level)
{
Check.notNull(world);
Check.notNull(level);
final String folder = world.getFolder();
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Extension.java
// public final class Extension
// {
// /** Image file extension (with dot). */
// public static final String IMAGE = ".png";
// /** Levels file extension (with dot). */
// public static final String LEVEL = ".wrl";
// /** Sounds file extension (with dot). */
// public static final String SFX = ".wav";
// /** Musics file extension (with dot). */
// public static final String MUSIC = ".xmi";
//
// /**
// * Private constructor.
// */
// private Extension()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/Level.java
import com.b3dgs.lionengine.Check;
import com.b3dgs.lionengine.LionEngineException;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.warcraft.constant.Extension;
import com.b3dgs.warcraft.constant.Folder;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of levels with their file.
*/
public enum Level
{
/** Forest level. */
FOREST(WorldType.FOREST, "forest"),
/** Swamp level. */
SWAMP(WorldType.SWAMP, "swamp");
/** Level file. */
private final Media level;
/** Level rip image. */
private final Media rip;
/**
* Create the level.
*
* @param world The level world (must not be <code>null</code>).
* @param level The level file name (must not be <code>null</code>).
* @throws LionEngineException If invalid argument.
*/
Level(WorldType world, String level)
{
Check.notNull(world);
Check.notNull(level);
final String folder = world.getFolder();
| this.level = Medias.create(Folder.MAPS, folder, level + Extension.LEVEL);
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/Level.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Extension.java
// public final class Extension
// {
// /** Image file extension (with dot). */
// public static final String IMAGE = ".png";
// /** Levels file extension (with dot). */
// public static final String LEVEL = ".wrl";
// /** Sounds file extension (with dot). */
// public static final String SFX = ".wav";
// /** Musics file extension (with dot). */
// public static final String MUSIC = ".xmi";
//
// /**
// * Private constructor.
// */
// private Extension()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
| import com.b3dgs.lionengine.Check;
import com.b3dgs.lionengine.LionEngineException;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.warcraft.constant.Extension;
import com.b3dgs.warcraft.constant.Folder;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of levels with their file.
*/
public enum Level
{
/** Forest level. */
FOREST(WorldType.FOREST, "forest"),
/** Swamp level. */
SWAMP(WorldType.SWAMP, "swamp");
/** Level file. */
private final Media level;
/** Level rip image. */
private final Media rip;
/**
* Create the level.
*
* @param world The level world (must not be <code>null</code>).
* @param level The level file name (must not be <code>null</code>).
* @throws LionEngineException If invalid argument.
*/
Level(WorldType world, String level)
{
Check.notNull(world);
Check.notNull(level);
final String folder = world.getFolder();
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Extension.java
// public final class Extension
// {
// /** Image file extension (with dot). */
// public static final String IMAGE = ".png";
// /** Levels file extension (with dot). */
// public static final String LEVEL = ".wrl";
// /** Sounds file extension (with dot). */
// public static final String SFX = ".wav";
// /** Musics file extension (with dot). */
// public static final String MUSIC = ".xmi";
//
// /**
// * Private constructor.
// */
// private Extension()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/Level.java
import com.b3dgs.lionengine.Check;
import com.b3dgs.lionengine.LionEngineException;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.warcraft.constant.Extension;
import com.b3dgs.warcraft.constant.Folder;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of levels with their file.
*/
public enum Level
{
/** Forest level. */
FOREST(WorldType.FOREST, "forest"),
/** Swamp level. */
SWAMP(WorldType.SWAMP, "swamp");
/** Level file. */
private final Media level;
/** Level rip image. */
private final Media rip;
/**
* Create the level.
*
* @param world The level world (must not be <code>null</code>).
* @param level The level file name (must not be <code>null</code>).
* @throws LionEngineException If invalid argument.
*/
Level(WorldType world, String level)
{
Check.notNull(world);
Check.notNull(level);
final String folder = world.getFolder();
| this.level = Medias.create(Folder.MAPS, folder, level + Extension.LEVEL);
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/Music.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Extension.java
// public final class Extension
// {
// /** Image file extension (with dot). */
// public static final String IMAGE = ".png";
// /** Levels file extension (with dot). */
// public static final String LEVEL = ".wrl";
// /** Sounds file extension (with dot). */
// public static final String SFX = ".wav";
// /** Musics file extension (with dot). */
// public static final String MUSIC = ".xmi";
//
// /**
// * Private constructor.
// */
// private Extension()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
| import java.util.Locale;
import com.b3dgs.lionengine.Check;
import com.b3dgs.lionengine.LionEngineException;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.warcraft.constant.Extension;
import com.b3dgs.warcraft.constant.Folder;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of available musics.
* <p>
* Music file name is enum name in lower case in enum race name in lower case folder.
* </p>
*/
public enum Music
{
/** Orc campaign 1. */
ORC_CAMPAIGN1(Race.ORC),
/** Orc campaign 2. */
ORC_CAMPAIGN2(Race.ORC),
/** Orc campaign 3. */
ORC_CAMPAIGN3(Race.ORC);
/** Associated media. */
private final Media media;
/**
* Create music.
*
* @param race The associated race (must not be <code>null</code>).
* @throws LionEngineException If invalid argument.
*/
Music(Race race)
{
Check.notNull(race);
final String folder = race.name().toLowerCase(Locale.ENGLISH);
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Extension.java
// public final class Extension
// {
// /** Image file extension (with dot). */
// public static final String IMAGE = ".png";
// /** Levels file extension (with dot). */
// public static final String LEVEL = ".wrl";
// /** Sounds file extension (with dot). */
// public static final String SFX = ".wav";
// /** Musics file extension (with dot). */
// public static final String MUSIC = ".xmi";
//
// /**
// * Private constructor.
// */
// private Extension()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/Music.java
import java.util.Locale;
import com.b3dgs.lionengine.Check;
import com.b3dgs.lionengine.LionEngineException;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.warcraft.constant.Extension;
import com.b3dgs.warcraft.constant.Folder;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of available musics.
* <p>
* Music file name is enum name in lower case in enum race name in lower case folder.
* </p>
*/
public enum Music
{
/** Orc campaign 1. */
ORC_CAMPAIGN1(Race.ORC),
/** Orc campaign 2. */
ORC_CAMPAIGN2(Race.ORC),
/** Orc campaign 3. */
ORC_CAMPAIGN3(Race.ORC);
/** Associated media. */
private final Media media;
/**
* Create music.
*
* @param race The associated race (must not be <code>null</code>).
* @throws LionEngineException If invalid argument.
*/
Music(Race race)
{
Check.notNull(race);
final String folder = race.name().toLowerCase(Locale.ENGLISH);
| final String file = name().toLowerCase(Locale.ENGLISH) + Extension.MUSIC;
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/Music.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Extension.java
// public final class Extension
// {
// /** Image file extension (with dot). */
// public static final String IMAGE = ".png";
// /** Levels file extension (with dot). */
// public static final String LEVEL = ".wrl";
// /** Sounds file extension (with dot). */
// public static final String SFX = ".wav";
// /** Musics file extension (with dot). */
// public static final String MUSIC = ".xmi";
//
// /**
// * Private constructor.
// */
// private Extension()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
| import java.util.Locale;
import com.b3dgs.lionengine.Check;
import com.b3dgs.lionengine.LionEngineException;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.warcraft.constant.Extension;
import com.b3dgs.warcraft.constant.Folder;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of available musics.
* <p>
* Music file name is enum name in lower case in enum race name in lower case folder.
* </p>
*/
public enum Music
{
/** Orc campaign 1. */
ORC_CAMPAIGN1(Race.ORC),
/** Orc campaign 2. */
ORC_CAMPAIGN2(Race.ORC),
/** Orc campaign 3. */
ORC_CAMPAIGN3(Race.ORC);
/** Associated media. */
private final Media media;
/**
* Create music.
*
* @param race The associated race (must not be <code>null</code>).
* @throws LionEngineException If invalid argument.
*/
Music(Race race)
{
Check.notNull(race);
final String folder = race.name().toLowerCase(Locale.ENGLISH);
final String file = name().toLowerCase(Locale.ENGLISH) + Extension.MUSIC;
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Extension.java
// public final class Extension
// {
// /** Image file extension (with dot). */
// public static final String IMAGE = ".png";
// /** Levels file extension (with dot). */
// public static final String LEVEL = ".wrl";
// /** Sounds file extension (with dot). */
// public static final String SFX = ".wav";
// /** Musics file extension (with dot). */
// public static final String MUSIC = ".xmi";
//
// /**
// * Private constructor.
// */
// private Extension()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/constant/Folder.java
// public final class Folder
// {
// /** Entities folder. */
// public static final String ENTITIES = "entity";
// /** Effects folder. */
// public static final String EFFECTS = "effect";
// /** Items folder. */
// public static final String ACTIONS = "action";
// /** Monsters folder. */
// public static final String ORCS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "orc");
// /** Sceneries folder. */
// public static final String HUMANS = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "human");
// /** Players folder. */
// public static final String NEUTRAL = UtilFolder.getPathSeparator(Medias.getSeparator(), ENTITIES, "neutral");
// /** Effects folder. */
// public static final String MAPS = "map";
// /** Fog of war folder. */
// public static final String FOG = "fog";
// /** Levels folder. */
// public static final String MENU = "menu";
// /** Musics folder. */
// public static final String MUSICS = "music";
// /** Sounds folder. */
// public static final String SOUNDS = "sfx";
//
// /**
// * Private constructor.
// */
// private Folder()
// {
// throw new LionEngineException(LionEngineException.ERROR_PRIVATE_CONSTRUCTOR);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/Music.java
import java.util.Locale;
import com.b3dgs.lionengine.Check;
import com.b3dgs.lionengine.LionEngineException;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.warcraft.constant.Extension;
import com.b3dgs.warcraft.constant.Folder;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft;
/**
* List of available musics.
* <p>
* Music file name is enum name in lower case in enum race name in lower case folder.
* </p>
*/
public enum Music
{
/** Orc campaign 1. */
ORC_CAMPAIGN1(Race.ORC),
/** Orc campaign 2. */
ORC_CAMPAIGN2(Race.ORC),
/** Orc campaign 3. */
ORC_CAMPAIGN3(Race.ORC);
/** Associated media. */
private final Media media;
/**
* Create music.
*
* @param race The associated race (must not be <code>null</code>).
* @throws LionEngineException If invalid argument.
*/
Music(Race race)
{
Check.notNull(race);
final String folder = race.name().toLowerCase(Locale.ENGLISH);
final String file = name().toLowerCase(Locale.ENGLISH) + Extension.MUSIC;
| media = Medias.create(Folder.MUSICS, folder, file.substring(race.name().length() + 1));
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/Decayable.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDead.java
// public class StateDead extends State
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDead(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
//
// @Override
// public void enter()
// {
// super.enter();
//
// model.getFeature(Layerable.class)
// .setLayer(Integer.valueOf(Constant.LAYER_CORPSE), Integer.valueOf(Constant.LAYER_CORPSE));
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadGold.java
// public final class StateDeadGold extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadGold(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadWood.java
// public final class StateDeadWood extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadWood(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
| import com.b3dgs.lionengine.AnimState;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.Tick;
import com.b3dgs.lionengine.Updatable;
import com.b3dgs.lionengine.game.feature.Animatable;
import com.b3dgs.lionengine.game.feature.FeatureGet;
import com.b3dgs.lionengine.game.feature.FeatureInterface;
import com.b3dgs.lionengine.game.feature.FeatureModel;
import com.b3dgs.lionengine.game.feature.Identifiable;
import com.b3dgs.lionengine.game.feature.Recyclable;
import com.b3dgs.lionengine.game.feature.Routine;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Spawner;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.state.StateHandler;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.state.StateDead;
import com.b3dgs.warcraft.object.state.StateDeadGold;
import com.b3dgs.warcraft.object.state.StateDeadWood;
|
checkCorpse = extrp ->
{
tick.update(extrp);
if (tick.elapsed(delay))
{
spawner.spawn(media, transformable)
.getFeature(Effect.class)
.start(transformable.getWidth(), transformable.getHeight());
pathfindable.clearPath();
identifiable.destroy();
}
};
checkDead = extrp ->
{
if (!tick.isStarted() && animatable.is(AnimState.FINISHED) && isDead())
{
tick.start();
check = checkCorpse;
}
};
}
/**
* Check if dead.
*
* @return <code>true</code> if dead, <code>false</code> else.
*/
private boolean isDead()
{
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDead.java
// public class StateDead extends State
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDead(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
//
// @Override
// public void enter()
// {
// super.enter();
//
// model.getFeature(Layerable.class)
// .setLayer(Integer.valueOf(Constant.LAYER_CORPSE), Integer.valueOf(Constant.LAYER_CORPSE));
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadGold.java
// public final class StateDeadGold extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadGold(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadWood.java
// public final class StateDeadWood extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadWood(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/Decayable.java
import com.b3dgs.lionengine.AnimState;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.Tick;
import com.b3dgs.lionengine.Updatable;
import com.b3dgs.lionengine.game.feature.Animatable;
import com.b3dgs.lionengine.game.feature.FeatureGet;
import com.b3dgs.lionengine.game.feature.FeatureInterface;
import com.b3dgs.lionengine.game.feature.FeatureModel;
import com.b3dgs.lionengine.game.feature.Identifiable;
import com.b3dgs.lionengine.game.feature.Recyclable;
import com.b3dgs.lionengine.game.feature.Routine;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Spawner;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.state.StateHandler;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.state.StateDead;
import com.b3dgs.warcraft.object.state.StateDeadGold;
import com.b3dgs.warcraft.object.state.StateDeadWood;
checkCorpse = extrp ->
{
tick.update(extrp);
if (tick.elapsed(delay))
{
spawner.spawn(media, transformable)
.getFeature(Effect.class)
.start(transformable.getWidth(), transformable.getHeight());
pathfindable.clearPath();
identifiable.destroy();
}
};
checkDead = extrp ->
{
if (!tick.isStarted() && animatable.is(AnimState.FINISHED) && isDead())
{
tick.start();
check = checkCorpse;
}
};
}
/**
* Check if dead.
*
* @return <code>true</code> if dead, <code>false</code> else.
*/
private boolean isDead()
{
| return stateHandler.isState(StateDead.class)
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/Decayable.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDead.java
// public class StateDead extends State
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDead(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
//
// @Override
// public void enter()
// {
// super.enter();
//
// model.getFeature(Layerable.class)
// .setLayer(Integer.valueOf(Constant.LAYER_CORPSE), Integer.valueOf(Constant.LAYER_CORPSE));
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadGold.java
// public final class StateDeadGold extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadGold(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadWood.java
// public final class StateDeadWood extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadWood(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
| import com.b3dgs.lionengine.AnimState;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.Tick;
import com.b3dgs.lionengine.Updatable;
import com.b3dgs.lionengine.game.feature.Animatable;
import com.b3dgs.lionengine.game.feature.FeatureGet;
import com.b3dgs.lionengine.game.feature.FeatureInterface;
import com.b3dgs.lionengine.game.feature.FeatureModel;
import com.b3dgs.lionengine.game.feature.Identifiable;
import com.b3dgs.lionengine.game.feature.Recyclable;
import com.b3dgs.lionengine.game.feature.Routine;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Spawner;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.state.StateHandler;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.state.StateDead;
import com.b3dgs.warcraft.object.state.StateDeadGold;
import com.b3dgs.warcraft.object.state.StateDeadWood;
| checkCorpse = extrp ->
{
tick.update(extrp);
if (tick.elapsed(delay))
{
spawner.spawn(media, transformable)
.getFeature(Effect.class)
.start(transformable.getWidth(), transformable.getHeight());
pathfindable.clearPath();
identifiable.destroy();
}
};
checkDead = extrp ->
{
if (!tick.isStarted() && animatable.is(AnimState.FINISHED) && isDead())
{
tick.start();
check = checkCorpse;
}
};
}
/**
* Check if dead.
*
* @return <code>true</code> if dead, <code>false</code> else.
*/
private boolean isDead()
{
return stateHandler.isState(StateDead.class)
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDead.java
// public class StateDead extends State
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDead(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
//
// @Override
// public void enter()
// {
// super.enter();
//
// model.getFeature(Layerable.class)
// .setLayer(Integer.valueOf(Constant.LAYER_CORPSE), Integer.valueOf(Constant.LAYER_CORPSE));
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadGold.java
// public final class StateDeadGold extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadGold(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadWood.java
// public final class StateDeadWood extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadWood(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/Decayable.java
import com.b3dgs.lionengine.AnimState;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.Tick;
import com.b3dgs.lionengine.Updatable;
import com.b3dgs.lionengine.game.feature.Animatable;
import com.b3dgs.lionengine.game.feature.FeatureGet;
import com.b3dgs.lionengine.game.feature.FeatureInterface;
import com.b3dgs.lionengine.game.feature.FeatureModel;
import com.b3dgs.lionengine.game.feature.Identifiable;
import com.b3dgs.lionengine.game.feature.Recyclable;
import com.b3dgs.lionengine.game.feature.Routine;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Spawner;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.state.StateHandler;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.state.StateDead;
import com.b3dgs.warcraft.object.state.StateDeadGold;
import com.b3dgs.warcraft.object.state.StateDeadWood;
checkCorpse = extrp ->
{
tick.update(extrp);
if (tick.elapsed(delay))
{
spawner.spawn(media, transformable)
.getFeature(Effect.class)
.start(transformable.getWidth(), transformable.getHeight());
pathfindable.clearPath();
identifiable.destroy();
}
};
checkDead = extrp ->
{
if (!tick.isStarted() && animatable.is(AnimState.FINISHED) && isDead())
{
tick.start();
check = checkCorpse;
}
};
}
/**
* Check if dead.
*
* @return <code>true</code> if dead, <code>false</code> else.
*/
private boolean isDead()
{
return stateHandler.isState(StateDead.class)
| || stateHandler.isState(StateDeadGold.class)
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/Decayable.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDead.java
// public class StateDead extends State
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDead(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
//
// @Override
// public void enter()
// {
// super.enter();
//
// model.getFeature(Layerable.class)
// .setLayer(Integer.valueOf(Constant.LAYER_CORPSE), Integer.valueOf(Constant.LAYER_CORPSE));
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadGold.java
// public final class StateDeadGold extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadGold(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadWood.java
// public final class StateDeadWood extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadWood(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
| import com.b3dgs.lionengine.AnimState;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.Tick;
import com.b3dgs.lionengine.Updatable;
import com.b3dgs.lionengine.game.feature.Animatable;
import com.b3dgs.lionengine.game.feature.FeatureGet;
import com.b3dgs.lionengine.game.feature.FeatureInterface;
import com.b3dgs.lionengine.game.feature.FeatureModel;
import com.b3dgs.lionengine.game.feature.Identifiable;
import com.b3dgs.lionengine.game.feature.Recyclable;
import com.b3dgs.lionengine.game.feature.Routine;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Spawner;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.state.StateHandler;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.state.StateDead;
import com.b3dgs.warcraft.object.state.StateDeadGold;
import com.b3dgs.warcraft.object.state.StateDeadWood;
| {
tick.update(extrp);
if (tick.elapsed(delay))
{
spawner.spawn(media, transformable)
.getFeature(Effect.class)
.start(transformable.getWidth(), transformable.getHeight());
pathfindable.clearPath();
identifiable.destroy();
}
};
checkDead = extrp ->
{
if (!tick.isStarted() && animatable.is(AnimState.FINISHED) && isDead())
{
tick.start();
check = checkCorpse;
}
};
}
/**
* Check if dead.
*
* @return <code>true</code> if dead, <code>false</code> else.
*/
private boolean isDead()
{
return stateHandler.isState(StateDead.class)
|| stateHandler.isState(StateDeadGold.class)
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDead.java
// public class StateDead extends State
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDead(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
//
// @Override
// public void enter()
// {
// super.enter();
//
// model.getFeature(Layerable.class)
// .setLayer(Integer.valueOf(Constant.LAYER_CORPSE), Integer.valueOf(Constant.LAYER_CORPSE));
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadGold.java
// public final class StateDeadGold extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadGold(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
//
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/state/StateDeadWood.java
// public final class StateDeadWood extends StateDead
// {
// /**
// * Create the state.
// *
// * @param model The model reference.
// * @param animation The animation reference.
// */
// StateDeadWood(EntityModel model, Animation animation)
// {
// super(model, animation);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/Decayable.java
import com.b3dgs.lionengine.AnimState;
import com.b3dgs.lionengine.Media;
import com.b3dgs.lionengine.Medias;
import com.b3dgs.lionengine.Tick;
import com.b3dgs.lionengine.Updatable;
import com.b3dgs.lionengine.game.feature.Animatable;
import com.b3dgs.lionengine.game.feature.FeatureGet;
import com.b3dgs.lionengine.game.feature.FeatureInterface;
import com.b3dgs.lionengine.game.feature.FeatureModel;
import com.b3dgs.lionengine.game.feature.Identifiable;
import com.b3dgs.lionengine.game.feature.Recyclable;
import com.b3dgs.lionengine.game.feature.Routine;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Spawner;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.state.StateHandler;
import com.b3dgs.lionengine.game.feature.tile.map.pathfinding.Pathfindable;
import com.b3dgs.warcraft.object.state.StateDead;
import com.b3dgs.warcraft.object.state.StateDeadGold;
import com.b3dgs.warcraft.object.state.StateDeadWood;
{
tick.update(extrp);
if (tick.elapsed(delay))
{
spawner.spawn(media, transformable)
.getFeature(Effect.class)
.start(transformable.getWidth(), transformable.getHeight());
pathfindable.clearPath();
identifiable.destroy();
}
};
checkDead = extrp ->
{
if (!tick.isStarted() && animatable.is(AnimState.FINISHED) && isDead())
{
tick.start();
check = checkCorpse;
}
};
}
/**
* Check if dead.
*
* @return <code>true</code> if dead, <code>false</code> else.
*/
private boolean isDead()
{
return stateHandler.isState(StateDead.class)
|| stateHandler.isState(StateDeadGold.class)
| || stateHandler.isState(StateDeadWood.class);
|
b3dgs/warcraft-remake | warcraft-game/src/main/java/com/b3dgs/warcraft/action/Attack.java | // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/EntitySfx.java
// @FeatureInterface
// public class EntitySfx extends FeatureModel
// {
// private static final String ATT_STARTED = "started";
// private static final String ATT_PRODUCED = "produced";
// private static final String ATT_SELECTED = "selected";
// private static final String ATT_ORDERED = "ordered";
// private static final String ATT_ATTACKED = "attacked";
//
// private final List<Sfx> started;
// private final List<Sfx> produced;
// private final List<Sfx> selected;
// private final List<Sfx> ordered;
// private final List<Sfx> attacked;
// private final List<Sfx> dead;
//
// private final Viewer viewer = services.get(Viewer.class);
// private final Player player = services.get(Player.class);
// private final FogOfWar fogOfWar = services.get(FogOfWar.class);
//
// @FeatureGet private Transformable transformable;
// @FeatureGet private Pathfindable pathfindable;
//
// /**
// * Create producing.
// *
// * @param services The services reference.
// * @param setup The setup reference.
// * @throws LionEngineException If invalid configuration.
// */
// public EntitySfx(Services services, Setup setup)
// {
// super(services, setup);
//
// started = Sfx.load(setup, ATT_STARTED);
// produced = Sfx.load(setup, ATT_PRODUCED);
// selected = Sfx.load(setup, ATT_SELECTED);
// ordered = Sfx.load(setup, ATT_ORDERED);
// attacked = Sfx.load(setup, ATT_ATTACKED);
// dead = Sfx.load(setup, Sfx.ATT_DEAD);
// }
//
// /**
// * Called on production started.
// */
// public void onStarted()
// {
// if (isVisible())
// {
// Sfx.playRandom(started);
// }
// }
//
// /**
// * Called on production ended.
// */
// public void onProduced()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(produced);
// }
// }
//
// /**
// * Called on selected.
// */
// public void onSelected()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(selected);
// }
// }
//
// /**
// * Called on ordered.
// */
// public void onOrdered()
// {
// if (isVisible())
// {
// Sfx.playRandom(ordered);
// }
// }
//
// /**
// * Called on attacked.
// */
// public void onAttacked()
// {
// if (isVisible())
// {
// Sfx.playRandom(attacked);
// }
// }
//
// /**
// * Called on dead.
// */
// public void onDead()
// {
// if (isVisible())
// {
// Sfx.playRandom(dead);
// }
// }
//
// /**
// * Check if visible on camera and not fogged.
// *
// * @return <code>true</code> if truly visible, <code>false</code> else.
// */
// private boolean isVisible()
// {
// return viewer.isViewable(transformable, 0, 0) && fogOfWar.isVisible(pathfindable);
// }
// }
| import java.util.List;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.attackable.Attacker;
import com.b3dgs.lionengine.game.feature.collidable.selector.Selectable;
import com.b3dgs.warcraft.object.feature.EntitySfx;
| /*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.action;
/**
* Attack action.
*/
public class Attack extends ActionModel
{
/**
* Create attack action.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Attack(Services services, Setup setup)
{
super(services, setup);
}
@Override
protected boolean assign()
{
final List<Selectable> selection = selector.getSelection();
final int n = selection.size();
for (int i = 0; i < n; i++)
{
final int tx = map.getInTileX(cursor);
final int ty = map.getInTileY(cursor);
final Selectable selectable = selection.get(i);
for (final Integer id : mapPath.getObjectsId(tx, ty))
{
final Transformable transformable = handler.get(id).getFeature(Transformable.class);
if (selectable.getFeature(Transformable.class) != transformable)
{
selectable.getFeature(Attacker.class).attack(transformable);
}
}
if (i == 0)
{
| // Path: warcraft-game/src/main/java/com/b3dgs/warcraft/object/feature/EntitySfx.java
// @FeatureInterface
// public class EntitySfx extends FeatureModel
// {
// private static final String ATT_STARTED = "started";
// private static final String ATT_PRODUCED = "produced";
// private static final String ATT_SELECTED = "selected";
// private static final String ATT_ORDERED = "ordered";
// private static final String ATT_ATTACKED = "attacked";
//
// private final List<Sfx> started;
// private final List<Sfx> produced;
// private final List<Sfx> selected;
// private final List<Sfx> ordered;
// private final List<Sfx> attacked;
// private final List<Sfx> dead;
//
// private final Viewer viewer = services.get(Viewer.class);
// private final Player player = services.get(Player.class);
// private final FogOfWar fogOfWar = services.get(FogOfWar.class);
//
// @FeatureGet private Transformable transformable;
// @FeatureGet private Pathfindable pathfindable;
//
// /**
// * Create producing.
// *
// * @param services The services reference.
// * @param setup The setup reference.
// * @throws LionEngineException If invalid configuration.
// */
// public EntitySfx(Services services, Setup setup)
// {
// super(services, setup);
//
// started = Sfx.load(setup, ATT_STARTED);
// produced = Sfx.load(setup, ATT_PRODUCED);
// selected = Sfx.load(setup, ATT_SELECTED);
// ordered = Sfx.load(setup, ATT_ORDERED);
// attacked = Sfx.load(setup, ATT_ATTACKED);
// dead = Sfx.load(setup, Sfx.ATT_DEAD);
// }
//
// /**
// * Called on production started.
// */
// public void onStarted()
// {
// if (isVisible())
// {
// Sfx.playRandom(started);
// }
// }
//
// /**
// * Called on production ended.
// */
// public void onProduced()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(produced);
// }
// }
//
// /**
// * Called on selected.
// */
// public void onSelected()
// {
// if (isVisible() && player.owns(this))
// {
// Sfx.playRandom(selected);
// }
// }
//
// /**
// * Called on ordered.
// */
// public void onOrdered()
// {
// if (isVisible())
// {
// Sfx.playRandom(ordered);
// }
// }
//
// /**
// * Called on attacked.
// */
// public void onAttacked()
// {
// if (isVisible())
// {
// Sfx.playRandom(attacked);
// }
// }
//
// /**
// * Called on dead.
// */
// public void onDead()
// {
// if (isVisible())
// {
// Sfx.playRandom(dead);
// }
// }
//
// /**
// * Check if visible on camera and not fogged.
// *
// * @return <code>true</code> if truly visible, <code>false</code> else.
// */
// private boolean isVisible()
// {
// return viewer.isViewable(transformable, 0, 0) && fogOfWar.isVisible(pathfindable);
// }
// }
// Path: warcraft-game/src/main/java/com/b3dgs/warcraft/action/Attack.java
import java.util.List;
import com.b3dgs.lionengine.game.feature.Services;
import com.b3dgs.lionengine.game.feature.Setup;
import com.b3dgs.lionengine.game.feature.Transformable;
import com.b3dgs.lionengine.game.feature.attackable.Attacker;
import com.b3dgs.lionengine.game.feature.collidable.selector.Selectable;
import com.b3dgs.warcraft.object.feature.EntitySfx;
/*
* Copyright (C) 2013-2022 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.b3dgs.warcraft.action;
/**
* Attack action.
*/
public class Attack extends ActionModel
{
/**
* Create attack action.
*
* @param services The services reference.
* @param setup The setup reference.
*/
public Attack(Services services, Setup setup)
{
super(services, setup);
}
@Override
protected boolean assign()
{
final List<Selectable> selection = selector.getSelection();
final int n = selection.size();
for (int i = 0; i < n; i++)
{
final int tx = map.getInTileX(cursor);
final int ty = map.getInTileY(cursor);
final Selectable selectable = selection.get(i);
for (final Integer id : mapPath.getObjectsId(tx, ty))
{
final Transformable transformable = handler.get(id).getFeature(Transformable.class);
if (selectable.getFeature(Transformable.class) != transformable)
{
selectable.getFeature(Attacker.class).attack(transformable);
}
}
if (i == 0)
{
| selectable.getFeature(EntitySfx.class).onOrdered();
|
pcalouche/spat | spat-services/src/main/java/com/pcalouche/spat/config/WebConfig.java | // Path: spat-services/src/main/java/com/pcalouche/spat/interceptors/LoggerInterceptor.java
// @Component
// public class LoggerInterceptor extends HandlerInterceptorAdapter {
// private static final Logger logger = LoggerFactory.getLogger(LoggerInterceptor.class);
//
// @Override
// public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// long startTime = System.currentTimeMillis();
// request.setAttribute("startTime", startTime);
// logger.debug(String.format("Starting request for time for %s", request.getRequestURL()));
// return true;
// }
//
// @Override
// public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
// long startTime = (Long) request.getAttribute("startTime");
// long endTime = System.currentTimeMillis();
// long executeTime = endTime - startTime;
// logger.debug((String.format("Execute time for %s was %d ms", request.getRequestURL(), executeTime)));
// }
// }
| import com.pcalouche.spat.interceptors.LoggerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | package com.pcalouche.spat.config;
@Configuration
public class WebConfig implements WebMvcConfigurer {
private final SpatProperties spatProperties; | // Path: spat-services/src/main/java/com/pcalouche/spat/interceptors/LoggerInterceptor.java
// @Component
// public class LoggerInterceptor extends HandlerInterceptorAdapter {
// private static final Logger logger = LoggerFactory.getLogger(LoggerInterceptor.class);
//
// @Override
// public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
// long startTime = System.currentTimeMillis();
// request.setAttribute("startTime", startTime);
// logger.debug(String.format("Starting request for time for %s", request.getRequestURL()));
// return true;
// }
//
// @Override
// public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
// long startTime = (Long) request.getAttribute("startTime");
// long endTime = System.currentTimeMillis();
// long executeTime = endTime - startTime;
// logger.debug((String.format("Execute time for %s was %d ms", request.getRequestURL(), executeTime)));
// }
// }
// Path: spat-services/src/main/java/com/pcalouche/spat/config/WebConfig.java
import com.pcalouche.spat.interceptors.LoggerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
package com.pcalouche.spat.config;
@Configuration
public class WebConfig implements WebMvcConfigurer {
private final SpatProperties spatProperties; | private final LoggerInterceptor loggerInterceptor; |
pcalouche/spat | spat-services/src/test/java/com/pcalouche/spat/api/controller/TeamControllerTest.java | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractControllerTest.java
// @ExtendWith(SpringExtension.class)
// @Import({
// SpatProperties.class,
// SecurityUtils.class,
// SecurityConfig.class
// })
// public abstract class AbstractControllerTest {
// @Autowired
// protected ObjectMapper objectMapper;
// @Autowired
// protected MockMvc mockMvc;
// @Autowired
// protected SecurityUtils securityUtils;
// @Autowired
// protected SpatProperties spatProperties;
// @MockBean
// protected LoggerInterceptor loggerInterceptor;
// @MockBean
// protected UserRepository userRepository;
// private String validUserToken;
// private String validAdminToken;
//
// protected String getValidUserToken() {
// if (validUserToken == null) {
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeUser", new HashSet<>());
// validUserToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validUserToken;
// }
//
// protected String getValidAdminToken() {
// if (validAdminToken == null) {
// Set<SimpleGrantedAuthority> authorities = Stream.of(new SimpleGrantedAuthority("Admin")).collect(Collectors.toSet());
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeAdmin", authorities);
// validAdminToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validAdminToken;
// }
//
// @BeforeEach
// public void setup() {
// // Mock the logger interceptor
// given(loggerInterceptor.preHandle(any(), any(), any())).willReturn(true);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/EndpointMessages.java
// public class EndpointMessages {
// public static final String CURRENT_USER_NOT_FOUND = "Unable to retrieve the current user.";
// public static final String NO_USER_FOUND = "No user found for id: %d.";
// public static final String USER_ALREADY_EXISTS = "A user already exists with username: %s.";
// public static final String NO_TEAM_FOUND = "No team found for id: %d.";
// public static final String TEAM_ALREADY_EXISTS = "A team already exists with name: %s.";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/Endpoints.java
// public class Endpoints {
// public static final String AUTH = "/auth";
// public static final String TOKEN = "/token";
// public static final String REFRESH_TOKEN = "/refresh-token";
// public static final String USERS = "/users";
// public static final String TEAMS = "/teams";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamService.java
// public interface TeamService {
// Optional<TeamDto> findById(Integer id);
//
// Optional<TeamDto> findByName(String name);
//
// List<TeamDto> findAll();
//
// TeamDto create(TeamEditRequest teamEditRequest);
//
// Optional<TeamDto> update(int id, TeamEditRequest teamEditRequest);
//
// void delete(Integer id);
// }
| import com.pcalouche.spat.AbstractControllerTest;
import com.pcalouche.spat.api.EndpointMessages;
import com.pcalouche.spat.api.Endpoints;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.service.TeamService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.Matchers.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | package com.pcalouche.spat.api.controller;
@WebMvcTest(TeamController.class)
public class TeamControllerTest extends AbstractControllerTest {
@MockBean | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractControllerTest.java
// @ExtendWith(SpringExtension.class)
// @Import({
// SpatProperties.class,
// SecurityUtils.class,
// SecurityConfig.class
// })
// public abstract class AbstractControllerTest {
// @Autowired
// protected ObjectMapper objectMapper;
// @Autowired
// protected MockMvc mockMvc;
// @Autowired
// protected SecurityUtils securityUtils;
// @Autowired
// protected SpatProperties spatProperties;
// @MockBean
// protected LoggerInterceptor loggerInterceptor;
// @MockBean
// protected UserRepository userRepository;
// private String validUserToken;
// private String validAdminToken;
//
// protected String getValidUserToken() {
// if (validUserToken == null) {
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeUser", new HashSet<>());
// validUserToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validUserToken;
// }
//
// protected String getValidAdminToken() {
// if (validAdminToken == null) {
// Set<SimpleGrantedAuthority> authorities = Stream.of(new SimpleGrantedAuthority("Admin")).collect(Collectors.toSet());
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeAdmin", authorities);
// validAdminToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validAdminToken;
// }
//
// @BeforeEach
// public void setup() {
// // Mock the logger interceptor
// given(loggerInterceptor.preHandle(any(), any(), any())).willReturn(true);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/EndpointMessages.java
// public class EndpointMessages {
// public static final String CURRENT_USER_NOT_FOUND = "Unable to retrieve the current user.";
// public static final String NO_USER_FOUND = "No user found for id: %d.";
// public static final String USER_ALREADY_EXISTS = "A user already exists with username: %s.";
// public static final String NO_TEAM_FOUND = "No team found for id: %d.";
// public static final String TEAM_ALREADY_EXISTS = "A team already exists with name: %s.";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/Endpoints.java
// public class Endpoints {
// public static final String AUTH = "/auth";
// public static final String TOKEN = "/token";
// public static final String REFRESH_TOKEN = "/refresh-token";
// public static final String USERS = "/users";
// public static final String TEAMS = "/teams";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamService.java
// public interface TeamService {
// Optional<TeamDto> findById(Integer id);
//
// Optional<TeamDto> findByName(String name);
//
// List<TeamDto> findAll();
//
// TeamDto create(TeamEditRequest teamEditRequest);
//
// Optional<TeamDto> update(int id, TeamEditRequest teamEditRequest);
//
// void delete(Integer id);
// }
// Path: spat-services/src/test/java/com/pcalouche/spat/api/controller/TeamControllerTest.java
import com.pcalouche.spat.AbstractControllerTest;
import com.pcalouche.spat.api.EndpointMessages;
import com.pcalouche.spat.api.Endpoints;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.service.TeamService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.Matchers.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
package com.pcalouche.spat.api.controller;
@WebMvcTest(TeamController.class)
public class TeamControllerTest extends AbstractControllerTest {
@MockBean | private TeamService teamService; |
pcalouche/spat | spat-services/src/test/java/com/pcalouche/spat/api/controller/TeamControllerTest.java | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractControllerTest.java
// @ExtendWith(SpringExtension.class)
// @Import({
// SpatProperties.class,
// SecurityUtils.class,
// SecurityConfig.class
// })
// public abstract class AbstractControllerTest {
// @Autowired
// protected ObjectMapper objectMapper;
// @Autowired
// protected MockMvc mockMvc;
// @Autowired
// protected SecurityUtils securityUtils;
// @Autowired
// protected SpatProperties spatProperties;
// @MockBean
// protected LoggerInterceptor loggerInterceptor;
// @MockBean
// protected UserRepository userRepository;
// private String validUserToken;
// private String validAdminToken;
//
// protected String getValidUserToken() {
// if (validUserToken == null) {
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeUser", new HashSet<>());
// validUserToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validUserToken;
// }
//
// protected String getValidAdminToken() {
// if (validAdminToken == null) {
// Set<SimpleGrantedAuthority> authorities = Stream.of(new SimpleGrantedAuthority("Admin")).collect(Collectors.toSet());
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeAdmin", authorities);
// validAdminToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validAdminToken;
// }
//
// @BeforeEach
// public void setup() {
// // Mock the logger interceptor
// given(loggerInterceptor.preHandle(any(), any(), any())).willReturn(true);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/EndpointMessages.java
// public class EndpointMessages {
// public static final String CURRENT_USER_NOT_FOUND = "Unable to retrieve the current user.";
// public static final String NO_USER_FOUND = "No user found for id: %d.";
// public static final String USER_ALREADY_EXISTS = "A user already exists with username: %s.";
// public static final String NO_TEAM_FOUND = "No team found for id: %d.";
// public static final String TEAM_ALREADY_EXISTS = "A team already exists with name: %s.";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/Endpoints.java
// public class Endpoints {
// public static final String AUTH = "/auth";
// public static final String TOKEN = "/token";
// public static final String REFRESH_TOKEN = "/refresh-token";
// public static final String USERS = "/users";
// public static final String TEAMS = "/teams";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamService.java
// public interface TeamService {
// Optional<TeamDto> findById(Integer id);
//
// Optional<TeamDto> findByName(String name);
//
// List<TeamDto> findAll();
//
// TeamDto create(TeamEditRequest teamEditRequest);
//
// Optional<TeamDto> update(int id, TeamEditRequest teamEditRequest);
//
// void delete(Integer id);
// }
| import com.pcalouche.spat.AbstractControllerTest;
import com.pcalouche.spat.api.EndpointMessages;
import com.pcalouche.spat.api.Endpoints;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.service.TeamService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.Matchers.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | package com.pcalouche.spat.api.controller;
@WebMvcTest(TeamController.class)
public class TeamControllerTest extends AbstractControllerTest {
@MockBean
private TeamService teamService; | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractControllerTest.java
// @ExtendWith(SpringExtension.class)
// @Import({
// SpatProperties.class,
// SecurityUtils.class,
// SecurityConfig.class
// })
// public abstract class AbstractControllerTest {
// @Autowired
// protected ObjectMapper objectMapper;
// @Autowired
// protected MockMvc mockMvc;
// @Autowired
// protected SecurityUtils securityUtils;
// @Autowired
// protected SpatProperties spatProperties;
// @MockBean
// protected LoggerInterceptor loggerInterceptor;
// @MockBean
// protected UserRepository userRepository;
// private String validUserToken;
// private String validAdminToken;
//
// protected String getValidUserToken() {
// if (validUserToken == null) {
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeUser", new HashSet<>());
// validUserToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validUserToken;
// }
//
// protected String getValidAdminToken() {
// if (validAdminToken == null) {
// Set<SimpleGrantedAuthority> authorities = Stream.of(new SimpleGrantedAuthority("Admin")).collect(Collectors.toSet());
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeAdmin", authorities);
// validAdminToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validAdminToken;
// }
//
// @BeforeEach
// public void setup() {
// // Mock the logger interceptor
// given(loggerInterceptor.preHandle(any(), any(), any())).willReturn(true);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/EndpointMessages.java
// public class EndpointMessages {
// public static final String CURRENT_USER_NOT_FOUND = "Unable to retrieve the current user.";
// public static final String NO_USER_FOUND = "No user found for id: %d.";
// public static final String USER_ALREADY_EXISTS = "A user already exists with username: %s.";
// public static final String NO_TEAM_FOUND = "No team found for id: %d.";
// public static final String TEAM_ALREADY_EXISTS = "A team already exists with name: %s.";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/Endpoints.java
// public class Endpoints {
// public static final String AUTH = "/auth";
// public static final String TOKEN = "/token";
// public static final String REFRESH_TOKEN = "/refresh-token";
// public static final String USERS = "/users";
// public static final String TEAMS = "/teams";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamService.java
// public interface TeamService {
// Optional<TeamDto> findById(Integer id);
//
// Optional<TeamDto> findByName(String name);
//
// List<TeamDto> findAll();
//
// TeamDto create(TeamEditRequest teamEditRequest);
//
// Optional<TeamDto> update(int id, TeamEditRequest teamEditRequest);
//
// void delete(Integer id);
// }
// Path: spat-services/src/test/java/com/pcalouche/spat/api/controller/TeamControllerTest.java
import com.pcalouche.spat.AbstractControllerTest;
import com.pcalouche.spat.api.EndpointMessages;
import com.pcalouche.spat.api.Endpoints;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.service.TeamService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.Matchers.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
package com.pcalouche.spat.api.controller;
@WebMvcTest(TeamController.class)
public class TeamControllerTest extends AbstractControllerTest {
@MockBean
private TeamService teamService; | private TeamDto testTeamDto1; |
pcalouche/spat | spat-services/src/test/java/com/pcalouche/spat/api/controller/TeamControllerTest.java | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractControllerTest.java
// @ExtendWith(SpringExtension.class)
// @Import({
// SpatProperties.class,
// SecurityUtils.class,
// SecurityConfig.class
// })
// public abstract class AbstractControllerTest {
// @Autowired
// protected ObjectMapper objectMapper;
// @Autowired
// protected MockMvc mockMvc;
// @Autowired
// protected SecurityUtils securityUtils;
// @Autowired
// protected SpatProperties spatProperties;
// @MockBean
// protected LoggerInterceptor loggerInterceptor;
// @MockBean
// protected UserRepository userRepository;
// private String validUserToken;
// private String validAdminToken;
//
// protected String getValidUserToken() {
// if (validUserToken == null) {
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeUser", new HashSet<>());
// validUserToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validUserToken;
// }
//
// protected String getValidAdminToken() {
// if (validAdminToken == null) {
// Set<SimpleGrantedAuthority> authorities = Stream.of(new SimpleGrantedAuthority("Admin")).collect(Collectors.toSet());
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeAdmin", authorities);
// validAdminToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validAdminToken;
// }
//
// @BeforeEach
// public void setup() {
// // Mock the logger interceptor
// given(loggerInterceptor.preHandle(any(), any(), any())).willReturn(true);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/EndpointMessages.java
// public class EndpointMessages {
// public static final String CURRENT_USER_NOT_FOUND = "Unable to retrieve the current user.";
// public static final String NO_USER_FOUND = "No user found for id: %d.";
// public static final String USER_ALREADY_EXISTS = "A user already exists with username: %s.";
// public static final String NO_TEAM_FOUND = "No team found for id: %d.";
// public static final String TEAM_ALREADY_EXISTS = "A team already exists with name: %s.";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/Endpoints.java
// public class Endpoints {
// public static final String AUTH = "/auth";
// public static final String TOKEN = "/token";
// public static final String REFRESH_TOKEN = "/refresh-token";
// public static final String USERS = "/users";
// public static final String TEAMS = "/teams";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamService.java
// public interface TeamService {
// Optional<TeamDto> findById(Integer id);
//
// Optional<TeamDto> findByName(String name);
//
// List<TeamDto> findAll();
//
// TeamDto create(TeamEditRequest teamEditRequest);
//
// Optional<TeamDto> update(int id, TeamEditRequest teamEditRequest);
//
// void delete(Integer id);
// }
| import com.pcalouche.spat.AbstractControllerTest;
import com.pcalouche.spat.api.EndpointMessages;
import com.pcalouche.spat.api.Endpoints;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.service.TeamService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.Matchers.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | package com.pcalouche.spat.api.controller;
@WebMvcTest(TeamController.class)
public class TeamControllerTest extends AbstractControllerTest {
@MockBean
private TeamService teamService;
private TeamDto testTeamDto1;
private TeamDto testTeamDto2;
@BeforeEach
public void before() {
testTeamDto1 = TeamDto.builder()
.id(1)
.name("Team1")
.build();
testTeamDto2 = TeamDto.builder()
.id(2)
.name("Team2")
.build();
}
@Test
public void testFindAll() throws Exception {
List<TeamDto> expectedTeamDtos = new ArrayList<>();
expectedTeamDtos.add(testTeamDto1);
expectedTeamDtos.add(testTeamDto2);
given(teamService.findAll()).willReturn(expectedTeamDtos);
| // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractControllerTest.java
// @ExtendWith(SpringExtension.class)
// @Import({
// SpatProperties.class,
// SecurityUtils.class,
// SecurityConfig.class
// })
// public abstract class AbstractControllerTest {
// @Autowired
// protected ObjectMapper objectMapper;
// @Autowired
// protected MockMvc mockMvc;
// @Autowired
// protected SecurityUtils securityUtils;
// @Autowired
// protected SpatProperties spatProperties;
// @MockBean
// protected LoggerInterceptor loggerInterceptor;
// @MockBean
// protected UserRepository userRepository;
// private String validUserToken;
// private String validAdminToken;
//
// protected String getValidUserToken() {
// if (validUserToken == null) {
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeUser", new HashSet<>());
// validUserToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validUserToken;
// }
//
// protected String getValidAdminToken() {
// if (validAdminToken == null) {
// Set<SimpleGrantedAuthority> authorities = Stream.of(new SimpleGrantedAuthority("Admin")).collect(Collectors.toSet());
// JwtAuthenticationToken jwtAuthenticationToken = new JwtAuthenticationToken("activeAdmin", authorities);
// validAdminToken = SecurityUtils.AUTH_HEADER_BEARER_PREFIX + securityUtils.createToken(jwtAuthenticationToken);
// }
// return validAdminToken;
// }
//
// @BeforeEach
// public void setup() {
// // Mock the logger interceptor
// given(loggerInterceptor.preHandle(any(), any(), any())).willReturn(true);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/EndpointMessages.java
// public class EndpointMessages {
// public static final String CURRENT_USER_NOT_FOUND = "Unable to retrieve the current user.";
// public static final String NO_USER_FOUND = "No user found for id: %d.";
// public static final String USER_ALREADY_EXISTS = "A user already exists with username: %s.";
// public static final String NO_TEAM_FOUND = "No team found for id: %d.";
// public static final String TEAM_ALREADY_EXISTS = "A team already exists with name: %s.";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/Endpoints.java
// public class Endpoints {
// public static final String AUTH = "/auth";
// public static final String TOKEN = "/token";
// public static final String REFRESH_TOKEN = "/refresh-token";
// public static final String USERS = "/users";
// public static final String TEAMS = "/teams";
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamService.java
// public interface TeamService {
// Optional<TeamDto> findById(Integer id);
//
// Optional<TeamDto> findByName(String name);
//
// List<TeamDto> findAll();
//
// TeamDto create(TeamEditRequest teamEditRequest);
//
// Optional<TeamDto> update(int id, TeamEditRequest teamEditRequest);
//
// void delete(Integer id);
// }
// Path: spat-services/src/test/java/com/pcalouche/spat/api/controller/TeamControllerTest.java
import com.pcalouche.spat.AbstractControllerTest;
import com.pcalouche.spat.api.EndpointMessages;
import com.pcalouche.spat.api.Endpoints;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.service.TeamService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.hamcrest.Matchers.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
package com.pcalouche.spat.api.controller;
@WebMvcTest(TeamController.class)
public class TeamControllerTest extends AbstractControllerTest {
@MockBean
private TeamService teamService;
private TeamDto testTeamDto1;
private TeamDto testTeamDto2;
@BeforeEach
public void before() {
testTeamDto1 = TeamDto.builder()
.id(1)
.name("Team1")
.build();
testTeamDto2 = TeamDto.builder()
.id(2)
.name("Team2")
.build();
}
@Test
public void testFindAll() throws Exception {
List<TeamDto> expectedTeamDtos = new ArrayList<>();
expectedTeamDtos.add(testTeamDto1);
expectedTeamDtos.add(testTeamDto2);
given(teamService.findAll()).willReturn(expectedTeamDtos);
| mockMvc.perform(MockMvcRequestBuilders.get(Endpoints.TEAMS) |
pcalouche/spat | spat-services/src/test/java/com/pcalouche/spat/service/TeamServiceTest.java | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractServiceTest.java
// @ExtendWith(SpringExtension.class)
// @DataJpaTest
// public abstract class AbstractServiceTest {
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
| import com.pcalouche.spat.AbstractServiceTest;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat; | package com.pcalouche.spat.service;
public class TeamServiceTest extends AbstractServiceTest {
@Autowired | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractServiceTest.java
// @ExtendWith(SpringExtension.class)
// @DataJpaTest
// public abstract class AbstractServiceTest {
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
// Path: spat-services/src/test/java/com/pcalouche/spat/service/TeamServiceTest.java
import com.pcalouche.spat.AbstractServiceTest;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
package com.pcalouche.spat.service;
public class TeamServiceTest extends AbstractServiceTest {
@Autowired | private TeamRepository teamRepository; |
pcalouche/spat | spat-services/src/test/java/com/pcalouche/spat/service/TeamServiceTest.java | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractServiceTest.java
// @ExtendWith(SpringExtension.class)
// @DataJpaTest
// public abstract class AbstractServiceTest {
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
| import com.pcalouche.spat.AbstractServiceTest;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat; | package com.pcalouche.spat.service;
public class TeamServiceTest extends AbstractServiceTest {
@Autowired
private TeamRepository teamRepository;
private TeamService teamService; | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractServiceTest.java
// @ExtendWith(SpringExtension.class)
// @DataJpaTest
// public abstract class AbstractServiceTest {
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
// Path: spat-services/src/test/java/com/pcalouche/spat/service/TeamServiceTest.java
import com.pcalouche.spat.AbstractServiceTest;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
package com.pcalouche.spat.service;
public class TeamServiceTest extends AbstractServiceTest {
@Autowired
private TeamRepository teamRepository;
private TeamService teamService; | private Team team1; |
pcalouche/spat | spat-services/src/test/java/com/pcalouche/spat/service/TeamServiceTest.java | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractServiceTest.java
// @ExtendWith(SpringExtension.class)
// @DataJpaTest
// public abstract class AbstractServiceTest {
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
| import com.pcalouche.spat.AbstractServiceTest;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat; | package com.pcalouche.spat.service;
public class TeamServiceTest extends AbstractServiceTest {
@Autowired
private TeamRepository teamRepository;
private TeamService teamService;
private Team team1;
private Team team2;
@BeforeEach
public void before() {
teamService = new TeamServiceImpl(teamRepository);
team1 = teamRepository.save(Team.builder()
.name("Team1")
.build());
team2 = teamRepository.save(Team.builder()
.name("Team2")
.build());
}
@Test
public void testFindById() {
assertThat(teamService.findById(team1.getId()))
.isEqualTo(
Optional.of( | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractServiceTest.java
// @ExtendWith(SpringExtension.class)
// @DataJpaTest
// public abstract class AbstractServiceTest {
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
// Path: spat-services/src/test/java/com/pcalouche/spat/service/TeamServiceTest.java
import com.pcalouche.spat.AbstractServiceTest;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
package com.pcalouche.spat.service;
public class TeamServiceTest extends AbstractServiceTest {
@Autowired
private TeamRepository teamRepository;
private TeamService teamService;
private Team team1;
private Team team2;
@BeforeEach
public void before() {
teamService = new TeamServiceImpl(teamRepository);
team1 = teamRepository.save(Team.builder()
.name("Team1")
.build());
team2 = teamRepository.save(Team.builder()
.name("Team2")
.build());
}
@Test
public void testFindById() {
assertThat(teamService.findById(team1.getId()))
.isEqualTo(
Optional.of( | TeamDto.builder() |
pcalouche/spat | spat-services/src/test/java/com/pcalouche/spat/service/TeamServiceTest.java | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractServiceTest.java
// @ExtendWith(SpringExtension.class)
// @DataJpaTest
// public abstract class AbstractServiceTest {
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
| import com.pcalouche.spat.AbstractServiceTest;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat; | public void testFindByName() {
assertThat(teamService.findByName(team1.getName()))
.isEqualTo(
Optional.of(
TeamDto.builder()
.id(team1.getId())
.name("Team1")
.build()
));
assertThat(teamService.findByName("bogus"))
.isEqualTo(Optional.empty());
}
@Test
public void testFindAll() {
assertThat(teamService.findAll()).containsOnly(
TeamDto.builder()
.id(team1.getId())
.name("Team1")
.build(),
TeamDto.builder()
.id(team2.getId())
.name("Team2")
.build()
);
}
@Test
public void testCreate() { | // Path: spat-services/src/test/java/com/pcalouche/spat/AbstractServiceTest.java
// @ExtendWith(SpringExtension.class)
// @DataJpaTest
// public abstract class AbstractServiceTest {
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
// Path: spat-services/src/test/java/com/pcalouche/spat/service/TeamServiceTest.java
import com.pcalouche.spat.AbstractServiceTest;
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
public void testFindByName() {
assertThat(teamService.findByName(team1.getName()))
.isEqualTo(
Optional.of(
TeamDto.builder()
.id(team1.getId())
.name("Team1")
.build()
));
assertThat(teamService.findByName("bogus"))
.isEqualTo(Optional.empty());
}
@Test
public void testFindAll() {
assertThat(teamService.findAll()).containsOnly(
TeamDto.builder()
.id(team1.getId())
.name("Team1")
.build(),
TeamDto.builder()
.id(team2.getId())
.name("Team2")
.build()
);
}
@Test
public void testCreate() { | TeamEditRequest teamEditRequest = TeamEditRequest.builder() |
pcalouche/spat | spat-services/src/main/java/com/pcalouche/spat/security/util/SecurityUtils.java | // Path: spat-services/src/main/java/com/pcalouche/spat/config/SpatProperties.java
// @Getter
// @Setter
// @Component
// @ConfigurationProperties(prefix = "spat")
// @Validated
// public class SpatProperties {
// /**
// * The current version. This is set use Spring Boot's automatic
// * property expansion.
// */
// private String version;
// /**
// * What origins to allow access from
// */
// private String[] corsAllowedOrigins;
// /**
// * The signing key used for JWTs.
// */
// @NotEmpty
// private String jwtSigningKey;
// /**
// * How long JWT tokens are good for
// */
// @NonNull
// private Duration jwtTokenDuration;
// /**
// * How long JWT refresh tokens are good for
// */
// @NotNull
// private Duration refreshTokenDuration;
// /**
// * The hostname of the environment
// */
// @NotEmpty
// private String hostname;
//
// public boolean isHttpsEnvironment() {
// return !"localhost".equals(hostname);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/User.java
// @Entity
// @Table(name = "users")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class User implements UserDetails {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String username;
// @NotBlank
// @Column(nullable = false)
// private String password;
// @Builder.Default
// private boolean accountNonExpired = true;
// @Builder.Default
// private boolean accountNonLocked = true;
// @Builder.Default
// private boolean credentialsNonExpired = true;
// @Builder.Default
// private boolean enabled = true;
// @ManyToMany(fetch = FetchType.EAGER)
// @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
// @Builder.Default
// private Set<Role> roles = new HashSet<>();
// @Transient
// @Setter(AccessLevel.NONE)
// private Set<SimpleGrantedAuthority> authorities;
//
// @Override
// public Set<SimpleGrantedAuthority> getAuthorities() {
// if (authorities == null) {
// authorities = new HashSet<>();
// if (roles != null) {
// for (Role role : roles) {
// authorities.add(new SimpleGrantedAuthority(role.getName()));
// }
// }
// }
// return authorities;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof User)) {
// return false;
// }
// User castedObj = (User) o;
// return Objects.equals(username, castedObj.getUsername());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(username);
// }
// }
| import com.pcalouche.spat.config.SpatProperties;
import com.pcalouche.spat.entity.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
import org.springframework.security.authentication.*;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import javax.crypto.SecretKey;
import javax.servlet.http.HttpServletRequest;
import java.util.Base64;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; | package com.pcalouche.spat.security.util;
@Component
public class SecurityUtils {
public static final PasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();
public static final String[] WHITELISTED_ENDPOINTS = {
// swagger endpoints
"/",
"/csrf",
"/error",
"/v3/api-docs/**",
"/swagger-ui.html",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui/**",
"/webjars/**",
"/favicon.ico",
// status endpoint
"/status"
};
public static final String AUTHENTICATED_PATH = "/**";
public static final String AUTH_HEADER_BASIC_PREFIX = "Basic ";
public static final String AUTH_HEADER_BEARER_PREFIX = "Bearer ";
public static final String CLAIMS_AUTHORITIES_KEY = "authorities";
public static final String CLAIMS_REFRESH_TOKEN_KEY = "refreshToken";
private static final String SIGNING_KEY = "Vlg1A40XMNUCLuMZ4h5qh5K4li3P3lqgqSLhNVNOBHqM9ZSnirtV+Hlcl4VOjfLI/shtzqmNNAnB8v0tvECJMQ==";
private final SecretKey secretKey; | // Path: spat-services/src/main/java/com/pcalouche/spat/config/SpatProperties.java
// @Getter
// @Setter
// @Component
// @ConfigurationProperties(prefix = "spat")
// @Validated
// public class SpatProperties {
// /**
// * The current version. This is set use Spring Boot's automatic
// * property expansion.
// */
// private String version;
// /**
// * What origins to allow access from
// */
// private String[] corsAllowedOrigins;
// /**
// * The signing key used for JWTs.
// */
// @NotEmpty
// private String jwtSigningKey;
// /**
// * How long JWT tokens are good for
// */
// @NonNull
// private Duration jwtTokenDuration;
// /**
// * How long JWT refresh tokens are good for
// */
// @NotNull
// private Duration refreshTokenDuration;
// /**
// * The hostname of the environment
// */
// @NotEmpty
// private String hostname;
//
// public boolean isHttpsEnvironment() {
// return !"localhost".equals(hostname);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/User.java
// @Entity
// @Table(name = "users")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class User implements UserDetails {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String username;
// @NotBlank
// @Column(nullable = false)
// private String password;
// @Builder.Default
// private boolean accountNonExpired = true;
// @Builder.Default
// private boolean accountNonLocked = true;
// @Builder.Default
// private boolean credentialsNonExpired = true;
// @Builder.Default
// private boolean enabled = true;
// @ManyToMany(fetch = FetchType.EAGER)
// @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
// @Builder.Default
// private Set<Role> roles = new HashSet<>();
// @Transient
// @Setter(AccessLevel.NONE)
// private Set<SimpleGrantedAuthority> authorities;
//
// @Override
// public Set<SimpleGrantedAuthority> getAuthorities() {
// if (authorities == null) {
// authorities = new HashSet<>();
// if (roles != null) {
// for (Role role : roles) {
// authorities.add(new SimpleGrantedAuthority(role.getName()));
// }
// }
// }
// return authorities;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof User)) {
// return false;
// }
// User castedObj = (User) o;
// return Objects.equals(username, castedObj.getUsername());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(username);
// }
// }
// Path: spat-services/src/main/java/com/pcalouche/spat/security/util/SecurityUtils.java
import com.pcalouche.spat.config.SpatProperties;
import com.pcalouche.spat.entity.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
import org.springframework.security.authentication.*;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import javax.crypto.SecretKey;
import javax.servlet.http.HttpServletRequest;
import java.util.Base64;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
package com.pcalouche.spat.security.util;
@Component
public class SecurityUtils {
public static final PasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder();
public static final String[] WHITELISTED_ENDPOINTS = {
// swagger endpoints
"/",
"/csrf",
"/error",
"/v3/api-docs/**",
"/swagger-ui.html",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui/**",
"/webjars/**",
"/favicon.ico",
// status endpoint
"/status"
};
public static final String AUTHENTICATED_PATH = "/**";
public static final String AUTH_HEADER_BASIC_PREFIX = "Basic ";
public static final String AUTH_HEADER_BEARER_PREFIX = "Bearer ";
public static final String CLAIMS_AUTHORITIES_KEY = "authorities";
public static final String CLAIMS_REFRESH_TOKEN_KEY = "refreshToken";
private static final String SIGNING_KEY = "Vlg1A40XMNUCLuMZ4h5qh5K4li3P3lqgqSLhNVNOBHqM9ZSnirtV+Hlcl4VOjfLI/shtzqmNNAnB8v0tvECJMQ==";
private final SecretKey secretKey; | private final SpatProperties spatProperties; |
pcalouche/spat | spat-services/src/main/java/com/pcalouche/spat/security/util/SecurityUtils.java | // Path: spat-services/src/main/java/com/pcalouche/spat/config/SpatProperties.java
// @Getter
// @Setter
// @Component
// @ConfigurationProperties(prefix = "spat")
// @Validated
// public class SpatProperties {
// /**
// * The current version. This is set use Spring Boot's automatic
// * property expansion.
// */
// private String version;
// /**
// * What origins to allow access from
// */
// private String[] corsAllowedOrigins;
// /**
// * The signing key used for JWTs.
// */
// @NotEmpty
// private String jwtSigningKey;
// /**
// * How long JWT tokens are good for
// */
// @NonNull
// private Duration jwtTokenDuration;
// /**
// * How long JWT refresh tokens are good for
// */
// @NotNull
// private Duration refreshTokenDuration;
// /**
// * The hostname of the environment
// */
// @NotEmpty
// private String hostname;
//
// public boolean isHttpsEnvironment() {
// return !"localhost".equals(hostname);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/User.java
// @Entity
// @Table(name = "users")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class User implements UserDetails {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String username;
// @NotBlank
// @Column(nullable = false)
// private String password;
// @Builder.Default
// private boolean accountNonExpired = true;
// @Builder.Default
// private boolean accountNonLocked = true;
// @Builder.Default
// private boolean credentialsNonExpired = true;
// @Builder.Default
// private boolean enabled = true;
// @ManyToMany(fetch = FetchType.EAGER)
// @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
// @Builder.Default
// private Set<Role> roles = new HashSet<>();
// @Transient
// @Setter(AccessLevel.NONE)
// private Set<SimpleGrantedAuthority> authorities;
//
// @Override
// public Set<SimpleGrantedAuthority> getAuthorities() {
// if (authorities == null) {
// authorities = new HashSet<>();
// if (roles != null) {
// for (Role role : roles) {
// authorities.add(new SimpleGrantedAuthority(role.getName()));
// }
// }
// }
// return authorities;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof User)) {
// return false;
// }
// User castedObj = (User) o;
// return Objects.equals(username, castedObj.getUsername());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(username);
// }
// }
| import com.pcalouche.spat.config.SpatProperties;
import com.pcalouche.spat.entity.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
import org.springframework.security.authentication.*;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import javax.crypto.SecretKey;
import javax.servlet.http.HttpServletRequest;
import java.util.Base64;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; | if (spatProperties.getJwtTokenDuration().compareTo(spatProperties.getRefreshTokenDuration()) > 0) {
throw new IllegalArgumentException("jwt token duration cannot be greater than refresh token duration");
}
this.spatProperties = spatProperties;
this.secretKey = Keys.hmacShaKeyFor(SIGNING_KEY.getBytes());
}
public static String[] getDecodedBasicAuthFromRequest(HttpServletRequest request) throws AuthenticationException {
String headerValue = request.getHeader(HttpHeaders.AUTHORIZATION);
if (headerValue != null && headerValue.startsWith(AUTH_HEADER_BASIC_PREFIX)) {
String encodedBase64String = headerValue.replace(AUTH_HEADER_BASIC_PREFIX, "");
String[] decodedBasicAuthorizationParts = new String(Base64.getDecoder().decode(encodedBase64String)).split(":");
if (decodedBasicAuthorizationParts.length != 2) {
throw new BadCredentialsException("Basic Authentication header is invalid");
} else {
return decodedBasicAuthorizationParts;
}
} else {
throw new BadCredentialsException("Basic Authentication header is invalid");
}
}
public static String getTokenFromRequest(HttpServletRequest request) {
String token = request.getHeader(HttpHeaders.AUTHORIZATION);
if (token != null && token.startsWith(AUTH_HEADER_BEARER_PREFIX)) {
token = token.replace(AUTH_HEADER_BEARER_PREFIX, "");
}
return token;
}
| // Path: spat-services/src/main/java/com/pcalouche/spat/config/SpatProperties.java
// @Getter
// @Setter
// @Component
// @ConfigurationProperties(prefix = "spat")
// @Validated
// public class SpatProperties {
// /**
// * The current version. This is set use Spring Boot's automatic
// * property expansion.
// */
// private String version;
// /**
// * What origins to allow access from
// */
// private String[] corsAllowedOrigins;
// /**
// * The signing key used for JWTs.
// */
// @NotEmpty
// private String jwtSigningKey;
// /**
// * How long JWT tokens are good for
// */
// @NonNull
// private Duration jwtTokenDuration;
// /**
// * How long JWT refresh tokens are good for
// */
// @NotNull
// private Duration refreshTokenDuration;
// /**
// * The hostname of the environment
// */
// @NotEmpty
// private String hostname;
//
// public boolean isHttpsEnvironment() {
// return !"localhost".equals(hostname);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/User.java
// @Entity
// @Table(name = "users")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class User implements UserDetails {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String username;
// @NotBlank
// @Column(nullable = false)
// private String password;
// @Builder.Default
// private boolean accountNonExpired = true;
// @Builder.Default
// private boolean accountNonLocked = true;
// @Builder.Default
// private boolean credentialsNonExpired = true;
// @Builder.Default
// private boolean enabled = true;
// @ManyToMany(fetch = FetchType.EAGER)
// @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
// @Builder.Default
// private Set<Role> roles = new HashSet<>();
// @Transient
// @Setter(AccessLevel.NONE)
// private Set<SimpleGrantedAuthority> authorities;
//
// @Override
// public Set<SimpleGrantedAuthority> getAuthorities() {
// if (authorities == null) {
// authorities = new HashSet<>();
// if (roles != null) {
// for (Role role : roles) {
// authorities.add(new SimpleGrantedAuthority(role.getName()));
// }
// }
// }
// return authorities;
// }
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof User)) {
// return false;
// }
// User castedObj = (User) o;
// return Objects.equals(username, castedObj.getUsername());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(username);
// }
// }
// Path: spat-services/src/main/java/com/pcalouche/spat/security/util/SecurityUtils.java
import com.pcalouche.spat.config.SpatProperties;
import com.pcalouche.spat.entity.User;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
import org.springframework.security.authentication.*;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import javax.crypto.SecretKey;
import javax.servlet.http.HttpServletRequest;
import java.util.Base64;
import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
if (spatProperties.getJwtTokenDuration().compareTo(spatProperties.getRefreshTokenDuration()) > 0) {
throw new IllegalArgumentException("jwt token duration cannot be greater than refresh token duration");
}
this.spatProperties = spatProperties;
this.secretKey = Keys.hmacShaKeyFor(SIGNING_KEY.getBytes());
}
public static String[] getDecodedBasicAuthFromRequest(HttpServletRequest request) throws AuthenticationException {
String headerValue = request.getHeader(HttpHeaders.AUTHORIZATION);
if (headerValue != null && headerValue.startsWith(AUTH_HEADER_BASIC_PREFIX)) {
String encodedBase64String = headerValue.replace(AUTH_HEADER_BASIC_PREFIX, "");
String[] decodedBasicAuthorizationParts = new String(Base64.getDecoder().decode(encodedBase64String)).split(":");
if (decodedBasicAuthorizationParts.length != 2) {
throw new BadCredentialsException("Basic Authentication header is invalid");
} else {
return decodedBasicAuthorizationParts;
}
} else {
throw new BadCredentialsException("Basic Authentication header is invalid");
}
}
public static String getTokenFromRequest(HttpServletRequest request) {
String token = request.getHeader(HttpHeaders.AUTHORIZATION);
if (token != null && token.startsWith(AUTH_HEADER_BEARER_PREFIX)) {
token = token.replace(AUTH_HEADER_BEARER_PREFIX, "");
}
return token;
}
| public static void validateUserAccountStatus(User user) { |
pcalouche/spat | spat-services/src/main/java/com/pcalouche/spat/service/TeamServiceImpl.java | // Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
| import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; | package com.pcalouche.spat.service;
@Service
public class TeamServiceImpl implements TeamService { | // Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamServiceImpl.java
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
package com.pcalouche.spat.service;
@Service
public class TeamServiceImpl implements TeamService { | private final TeamRepository teamRepository; |
pcalouche/spat | spat-services/src/main/java/com/pcalouche/spat/service/TeamServiceImpl.java | // Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
| import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; | package com.pcalouche.spat.service;
@Service
public class TeamServiceImpl implements TeamService {
private final TeamRepository teamRepository;
public TeamServiceImpl(TeamRepository teamRepository) {
this.teamRepository = teamRepository;
}
@Override
@Transactional(readOnly = true) | // Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamServiceImpl.java
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
package com.pcalouche.spat.service;
@Service
public class TeamServiceImpl implements TeamService {
private final TeamRepository teamRepository;
public TeamServiceImpl(TeamRepository teamRepository) {
this.teamRepository = teamRepository;
}
@Override
@Transactional(readOnly = true) | public Optional<TeamDto> findById(Integer id) { |
pcalouche/spat | spat-services/src/main/java/com/pcalouche/spat/service/TeamServiceImpl.java | // Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
| import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; | package com.pcalouche.spat.service;
@Service
public class TeamServiceImpl implements TeamService {
private final TeamRepository teamRepository;
public TeamServiceImpl(TeamRepository teamRepository) {
this.teamRepository = teamRepository;
}
@Override
@Transactional(readOnly = true)
public Optional<TeamDto> findById(Integer id) {
return teamRepository.findById(id)
.map(TeamDto::map);
}
@Override
public Optional<TeamDto> findByName(String name) {
return teamRepository.findByName(name)
.map(TeamDto::map);
}
@Override
@Transactional(readOnly = true)
public List<TeamDto> findAll() {
return teamRepository.findAll(Sort.by("name")).stream()
.map(TeamDto::map)
.collect(Collectors.toList());
}
@Override
@Transactional | // Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamDto.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamDto {
// @EqualsAndHashCode.Exclude
// private Integer id;
// private String name;
//
// public static TeamDto map(Team team) {
// return TeamDto.builder()
// .id(team.getId())
// .name(team.getName())
// .build();
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/api/dto/TeamEditRequest.java
// @Data
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class TeamEditRequest {
// @NotEmpty
// private String name;
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/entity/Team.java
// @Entity
// @Table(name = "teams")
// @Getter
// @Setter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public class Team {
// @Id
// @GeneratedValue(strategy = GenerationType.IDENTITY)
// private Integer id;
// @NotBlank
// @Column(unique = true, nullable = false)
// private String name;
//
// @Override
// public boolean equals(Object o) {
// if (this == o) {
// return true;
// }
// if (!(o instanceof Team)) {
// return false;
// }
// Team castedObj = (Team) o;
// return Objects.equals(name, castedObj.getName());
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
// }
//
// Path: spat-services/src/main/java/com/pcalouche/spat/repository/TeamRepository.java
// @Repository
// public interface TeamRepository extends JpaRepository<Team, Integer> {
// Optional<Team> findByName(String name);
// }
// Path: spat-services/src/main/java/com/pcalouche/spat/service/TeamServiceImpl.java
import com.pcalouche.spat.api.dto.TeamDto;
import com.pcalouche.spat.api.dto.TeamEditRequest;
import com.pcalouche.spat.entity.Team;
import com.pcalouche.spat.repository.TeamRepository;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
package com.pcalouche.spat.service;
@Service
public class TeamServiceImpl implements TeamService {
private final TeamRepository teamRepository;
public TeamServiceImpl(TeamRepository teamRepository) {
this.teamRepository = teamRepository;
}
@Override
@Transactional(readOnly = true)
public Optional<TeamDto> findById(Integer id) {
return teamRepository.findById(id)
.map(TeamDto::map);
}
@Override
public Optional<TeamDto> findByName(String name) {
return teamRepository.findByName(name)
.map(TeamDto::map);
}
@Override
@Transactional(readOnly = true)
public List<TeamDto> findAll() {
return teamRepository.findAll(Sort.by("name")).stream()
.map(TeamDto::map)
.collect(Collectors.toList());
}
@Override
@Transactional | public TeamDto create(TeamEditRequest teamEditRequest) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.