What is the equivalent of #RunWith(Enclosed.class) in JUnit 5? - junit4

What is the equivalent ExtendsWith annotation for #RunWith(Enclosed.class) in JUnit5?

You can do this using the #Nested annotation in your sub-classes, according to the JUnit5 documentation.
Example
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.EmptyStackException;
import java.util.Stack;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
#DisplayName("A stack")
class TestingAStackDemo {
Stack<Object> stack;
#Test
#DisplayName("is instantiated with new Stack()")
void isInstantiatedWithNew() {
new Stack<>();
}
#Nested
#DisplayName("when new")
class WhenNew {
#BeforeEach
void createNewStack() {
stack = new Stack<>();
}
#Test
#DisplayName("is empty")
void isEmpty() {
assertTrue(stack.isEmpty());
}
#Test
#DisplayName("throws EmptyStackException when popped")
void throwsExceptionWhenPopped() {
assertThrows(EmptyStackException.class, stack::pop);
}
#Test
#DisplayName("throws EmptyStackException when peeked")
void throwsExceptionWhenPeeked() {
assertThrows(EmptyStackException.class, stack::peek);
}
#Nested
#DisplayName("after pushing an element")
class AfterPushing {
String anElement = "an element";
#BeforeEach
void pushAnElement() {
stack.push(anElement);
}
#Test
#DisplayName("it is no longer empty")
void isNotEmpty() {
assertFalse(stack.isEmpty());
}
#Test
#DisplayName("returns the element when popped and is empty")
void returnElementWhenPopped() {
assertEquals(anElement, stack.pop());
assertTrue(stack.isEmpty());
}
#Test
#DisplayName("returns the element when peeked but remains not empty")
void returnElementWhenPeeked() {
assertEquals(anElement, stack.peek());
assertFalse(stack.isEmpty());
}
}
}
}

Related

I want to create a plugin using biometric authentication (Biometric) provided by Google and implement it in Unity

I would like to implement biometric authentication using the biometrics provided by Googole, but I am having trouble getting it to work.
The following is a reference site on biometrics.
https://developer.android.com/jetpack/androidx/releases/biometric
I've never made an Android plugin before, and I'm having a hard time finding information on how to integrate with Unity.
I'm testing it with the following code
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/activity/ComponentActivity;
java.lang.ClassNotFoundException: androidx.activity.ComponentActivity
I'm getting an error and don't know how to fix it.
Please help me. Please help me.
◇MainActivity.java
package com.example.biometricslibs;
import android.content.Context;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.biometric.BiometricPrompt;
import androidx.fragment.app.FragmentActivity;
import java.util.concurrent.Executor;
public class MainActivity {
public static MainActivity instance() {
return new MainActivity();
}
private Executor executor = new MainThreadExecutor();
private BiometricPrompt biometricPrompt;
private BiometricPrompt.AuthenticationCallback callback = new BiometricPrompt.AuthenticationCallback() {
#Override
public void onAuthenticationError(int errorCode, #NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
if (errorCode == 13 && biometricPrompt != null)
biometricPrompt.cancelAuthentication();
}
#Override
public void onAuthenticationSucceeded(#NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
}
#Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
};
public void BiometricCheck(Context context) {
Toast.makeText(context, "call", Toast.LENGTH_SHORT).show();
biometricPrompt = new BiometricPrompt((FragmentActivity) context, executor, callback);
BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("title")
.setSubtitle("subTitle")
.setDescription("description")
.setNegativeButtonText("cancel")
.build();
biometricPrompt.authenticate(promptInfo);
}
}
◇MainThreadExecutor.java
package com.example.biometricslibs;
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.Executor;
public class MainThreadExecutor implements Executor {
private final Handler handler = new Handler(Looper.getMainLooper());
#Override
public void execute(Runnable r) {
handler.post(r);
}
}
◇UnityC#
using(var nativeDialog = new AndroidJavaClass("com.example.biometricslibs.MainActivity"))
{
using(var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using(var currentUnityActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
{
using(var instance = nativeDialog.CallStatic<AndroidJavaObject>("instance"))
{
instance.Call(
"BiometricCheck",
currentUnityActivity
);
}
}
}
}

Giving a player an item (minecraft plugin)

my code is
package me.Doloro.FerretSBPlugin;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class YourMistakesHelpMe {
#SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("bruh")) {
Player player = (Player) sender;
player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
sender.sendMessage(org.bukkit.ChatColor.BLUE + "Check Your Inventory");
return true;
} //If this has happened the function will return true.
// If this hasn't happened the value of false will be returned.
return false;
}
}
I want to to give a Diamond_Sword when the command is typed
there is no error only a {player} has used the command /bruh
, Also I am new to coding this so any help would help me a LOT
So it might be because you forgot the "implements CommandExecutor" after "public class YourMistakesHelpMe". I can't check it rn but idk why it wouldn't work.
package me.Doloro.FerretSBPlugin;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class YourMistakesHelpMe implements CommandExecutor {
#SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("bruh")) {
Player player = (Player) sender;
player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
sender.sendMessage(org.bukkit.ChatColor.BLUE + "Check Your Inventory");
return true;
} //If this has happened the function will return true.
// If this hasn't happened the value of false will be returned.
return false;
}
}

JavaScript method window.open() is not opening new window in my JavaFX browser

I have built an web browser in JavaFX. I want to add new popup window feature in my browser. when I use JavaScript method window.open(). It will execute code and open new popup window.
package browser;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.concurrent.Worker.State;
import javafx.event.ActionEvent;
import javafx.event.EventTarget;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.JOptionPane;
import netscape.javascript.JSObject;
public class BrowserController implements Initializable {
#FXML
BorderPane browserBP;
#FXML
WebView browserWV;
#FXML
ImageView stopReloadIV;
#FXML
TextField addressBarTF;
#FXML
ProgressIndicator progressPI;
#FXML
Label statusL;
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb)
{
popup pop_up = new popup();
browserWV.getEngine().getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>()
{
#Override
public void changed(ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) {
statusL.setText("loading... " + browserWV.getEngine().getLocation());
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/stoploading.png")));
progressPI.setVisible(true);
if(newValue == Worker.State.SUCCEEDED) {
//
JSObject window = (JSObject) browserWV.getEngine().executeScript("window");
window.setMember("window",pop_up);
addressBarTF.setText(browserWV.getEngine().getLocation());
statusL.setText("loaded");
progressPI.setVisible(false);
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/reload.png")));
if(browserBP.getParent() != null) {
TabPane tp = (TabPane)browserBP.getParent().getParent();
for(Tab tab : tp.getTabs()) {
if(tab.getContent() == browserBP) {
tab.setText(browserWV.getEngine().getTitle());
break;
}
}
}
}
}
});
WebEngine webEngine = browserWV.getEngine();
webEngine.setJavaScriptEnabled(true);
}
#FXML
private void browserBackButtonAction(ActionEvent event) {
if(browserWV.getEngine().getHistory().getCurrentIndex() <= 0) {
return;
}
browserWV.getEngine().getHistory().go(-1);
}
#FXML
private void browserForwardButtonAction(ActionEvent event) {
if((browserWV.getEngine().getHistory().getCurrentIndex() + 1) >= browserWV.getEngine().getHistory().getEntries().size()) {
return;
}
browserWV.getEngine().getHistory().go(1);
}
#FXML
private void browserGoButtonAction(ActionEvent event) {
String url = addressBarTF.getText().trim();
/*if(url.isEmpty())
{
JOptionPane.showMessageDialog(null, "No url provided");
return;
}
if(!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://"+url;
}*/
browserWV.getEngine().load(url);
//browserStopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/stoploading.png")));
}
#FXML
private void browserStopReloadButtonAction(ActionEvent event) {
if(browserWV.getEngine().getLoadWorker().isRunning()) {
browserWV.getEngine().getLoadWorker().cancel();
statusL.setText("loaded");
progressPI.setVisible(false);
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/reload.png")));
} else {
browserWV.getEngine().reload();
stopReloadIV.setImage(new Image(getClass().getResourceAsStream("/images/stoploading.png")));
}
}
#FXML
private void browserHomeButtonAction(ActionEvent event) {
browserWV.getEngine().loadContent("<html><title>New Tab</title></html>");
addressBarTF.setText("");
}
private TextField setText(String ur1) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
It's popup class to open new popup window.But when I use window.open method in JavaScript. It's working but in same window.How it will be open in new window?
package browser;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.web.PopupFeatures;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Callback;
import static sun.plugin.javascript.navig.JSType.URL;
public class popup
{
public void open(String url)
{
WebView browserWV = new WebView();
Platform.runLater(new Runnable()
{
#Override
public void run()
{
browserWV.getEngine().setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>()
{
#Override
public WebEngine call(PopupFeatures p) {
Stage stage = new Stage(StageStyle.UTILITY);
WebView wv2 = new WebView();
stage.setScene(new Scene(wv2));
stage.show();
WebEngine webEngine = new WebEngine();
webEngine.setJavaScriptEnabled(true);
return wv2.getEngine();
}
});
VBox root = new VBox();
TextField address_bar = new TextField();
root.getChildren().add(address_bar);
root.getChildren().add(browserWV);
Scene scene = new Scene(root, 1370, 700);
Stage primaryStage = new Stage();
primaryStage.setTitle("Popup");
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setIconified(true);
browserWV.getEngine().load(url);
address_bar.setText(browserWV.getEngine().getLocation());
}
});
}
}

Not able to store value getting from Transliteration using GWT

I am new to GWT and I want to make a application in which words are transliterate and store in a varible.which can be used for storing values in database.
But when I am trying to store in variable it gives null value when am printing it.
package com.google.gwt.language.sample.hellolanguage.client;
import java.util.ArrayList;
import java.util.List;
import com.google.gwt.language.client.transliteration.LanguageCode;
import com.google.gwt.language.client.transliteration.SupportedDestinationLanguages;
import com.google.gwt.language.client.transliteration.control.TransliterationControl;
import com.google.gwt.language.client.transliteration.control.TransliterationControlOptions;
import com.google.gwt.language.client.transliteration.text.Transliteration;
import com.google.gwt.language.client.transliteration.text.TransliterationCallback;
import com.google.gwt.language.client.transliteration.text.TransliterationResult;
import com.google.gwt.user.client.ui.Composite;
public class Trans extends Composite {
ArrayList<String> wordsArray= new ArrayList<String>();
public String sss;
public void recieve(String ss)
{
this.sss=ss;
System.out.println(sss);
}
public String send(){
return sss;
}
public Trans(ArrayList<String> str) {
initTransliterationControls(str);
//Here I want to print
System.out.println(sss);
}
public void initTransliterationControls(ArrayList<String> wordsArray1) {
//ArrayList<String> wordsArray= new ArrayList<String>();
// wordsArray=wordsArray1;
//System.out.println(wordsArray1.size());
// for(int i=0;i<wordsArray1.size();i++)
//{
//wordsArray.add(wordsArray1.get(i).toString());
//}
wordsArray.add(wordsArray1.get(0).toString());
wordsArray.add("Rerrebok");
wordsArray.add("Woodland j_74_Hi-gh Heels Boots");
//System.out.println(wordsArray);
Transliteration.transliterate(wordsArray, LanguageCode.ENGLISH,
LanguageCode.HINDI, new TransliterationCallback() {
#Override
public void onCallback(TransliterationResult result) {
// System.out.println(result.getTransliterations().toString());
List<List<String>> collection= new ArrayList<List<String>>();
collection=result.getTransliterations();
// Here I am storing it on sss but when I am print outside this function it gives Null
sss=collection.get(0).get(0).toString();
}
});
}
}

Jenkins Plugin. RootAction. index.jelly in seperate window

i am writing a simple plugin and am forced to create a RootAction which displays a page (the index.jelly) and needs some additional values to confirm and then execute the methode.
My problem is, that the index.jelly file gets always displayed on a blank window.
But i do need it to be included inside of the Jenkinstemplate in the main table, as usual.
Can't seem to figure out why this is happening.
Any ideas?
RestartJksLink.java
package org.jenkinsci.plugins.tomcat_app_restart;
import hudson.Extension;
import hudson.model.ManagementLink;
/**
*
*
* #author [...]
*/
#Extension
public class RestartJksLink extends ManagementLink {
#Override
public String getIconFileName() {
return "/plugin/tomcat-app-restart/images/restart.png";
}
#Override
public String getUrlName() {
return "jksrestart";
}
#Override
public String getDescription() {
return "Restart your Jenkins-Application on Tomcat";
}
public String getDisplayName() {
return "Restart Jenkins-App on Tomcat";
}
}
RestartJksRootAction.java
package org.jenkinsci.plugins.tomcat_app_restart;
import java.io.IOException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import jenkins.model.Jenkins;
import hudson.Extension;
import hudson.model.RootAction;
import hudson.util.FormValidation;
#Extension
public class RestartJksRootAction implements RootAction {
public String getDisplayName() {
return "Restart Jenkins on Tomcat";
}
public String getIconFileName() {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
return null;
}
if (!Jenkins.getInstance().getLifecycle().canRestart()) {
return null;
}
return "/plugin/tomcat-app-restart/images/restart.png";
}
public String getUrlName() {
return "jksrestart";
}
public FormValidation doJksRestart() {
Authenticator.setDefault (new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication ("admin", "admin".toCharArray());
}
});
URL url;
try {
url = new URL("http://localhost:8888/manager/text/start?path=/jenkins");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
System.out.println("" + connection.getResponseMessage());
return FormValidation.ok("Success");
} catch (IOException e) {
return FormValidation.error("Client error: " + e.getMessage());
}
}
}
index.jelly inside: resources.org.jenkinsci.plugins.tomcat_app_restart.RestartJksRootAction
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:validateButton
title="${%Restart Jenkins}" progress="${%Restarting...}"
method="JksRestart" with="" />
</j:jelly>
Thank you guys!
I am new to jenkins plugin development, this would help me a lot to understand.
Kind regards.
this demo (rootaction-example-plugin) helped a lot.You can read it.
https://github.com/gustavohenrique/jenkins-plugins/tree/master/rootaction-example-plugin
Add the <l:main-panel> tag and the the <l:layout norefresh="true">tag to the index.jelly file.
And include the side panel:
Pass the the build to Action (through a parameter of the constructor)
The build can be retrieved out of the parameters of the perform method which is inherited from the BuildStepCompatibilityLayer class (by Extending Publisher).
Create a getBuild() method in the Action class
Add the <st:include it="${it.build}" page="sidepanel.jelly" /> tag with the build
Jelly Example (index.jelly):
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<l:layout norefresh="true">
<st:include it="${it.build}" page="sidepanel.jelly" />
<l:main-panel>
<f:validateButton title="${%Restart Jenkins}" progress="${%Restarting...}" method="JksRestart" with="" />
</l:main-panel>
</l:layout>
</j:jelly>
Java Action class example:
package tryPublisher.tryPublisher;
import hudson.model.Action;
import hudson.model.AbstractBuild;
public class ExampleAction implements Action {
AbstractBuild<?,?> build;
public ExampleAction(AbstractBuild<?,?> build) {
this.build = build;
}
#Override
public String getIconFileName() {
return "/plugin/action.png";
}
#Override
public String getDisplayName() {
return "ExampleAction";
}
#Override
public String getUrlName() {
return "ExampleActionUrl";
}
public AbstractBuild<?,?> getBuild() {
return this.build;
}
}
Java Publisher class example:
package tryPublisher.tryPublisher;
import java.io.IOException;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
public class ExamplePublisher extends Publisher {
#Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}
#Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) throws InterruptedException, IOException {
build.getActions().add(new ExampleAction(build));
return true;
}
}
The .jelly file has to be in the right resources map of the plugin project. In a map with the same name as the name of the Java class implementing Action. The name of the .jelly is important also.