Posts by Fagner Fonseca • 1,447 points
61 posts
-
2
votes1
answer47
viewsA: problems using fail in junit
1 - To accomplish what you want, just pass the message on checkThat thus: error.checkThat("O valor do tipo indicio que está no arquivo CSV não existe no banco de dados",…
-
0
votes1
answer189
viewsA: function equals of object is not called during unit test
Apparently there’s a problem with the design of your test. Why create a spy of that class ProvTO? You create the spy, but in no time do I see you using the verify. The spy is used to verify class…
-
2
votes2
answers95
viewsA: What is the best way to define access to the methods of a class I want to use for unit testing?
You don’t need to leave your public method to be able to test it. Ideally, only public methods should be tested. If your method is private, it means some public method will call you. You can perform…
-
2
votes2
answers406
viewsA: What is the purpose of the Interfaces used in a Mock?
In fact, to create a mock, you don’t need an interface. You can create a mock of a class. What will define is how you designed your solution. When you use an interface and when you use a class you…
-
3
votes1
answer496
viewsA: How to check if a file has been added to a java directory?
You can use the class WatchService package java.nio.file. Create the service: WatchService watcher = FileSystems.getDefault().newWatchService(); Record the path that will be heard. Registration has…
-
1
votes1
answer34
viewsA: Javafx imput in textfields
The desired action can be implemented in the method setOnMouseClicked of the button, that way: btn.setOnMouseClicked((event) -> { x = Integer.parseInt(tlLinhas.getText()); y =…
javafxanswered Fagner Fonseca 1,447 -
1
votes1
answer147
viewsA: Where to store binary files in Junit Unit tests with Maven?
The correct is to put it in this directory. When you run the test, the files will be read in Runtime, only in the test Runtime. So what the documentation says is also correct. You must create a…
-
5
votes1
answer3287
viewsA: Error using Mock: Wanted but not Invoked: Actually, there Were zero interactions with this mock
You are checking whether the method pi() is called once, but you don’t call him at any time. That’s exactly what the error is saying: Wanted but not Invoked: Actually, there Were zero interactions…
-
1
votes1
answer312
viewsA: Classes Parameterized with Junit 4
The problem is that you have committed a certain confusion in the method assertEquals. This method receives the parameters in that order: assertEquals(valorEsperado, valorAtualQueFoiRetornado)…
-
1
votes1
answer188
viewsA: Rename worksheet tab
The problem is that you are changing the tab name in memory only. You need to call the workbook.write to write your changes to the file. Example: String inputPath = "path"; FileInputStream…
-
1
votes2
answers906
viewsA: Printing java Boolean attributes
In situations like this, you should go to the class and check if the method you want has been declared. When Intellisense does not show the method/attribute, it means either the method/attribute…
-
3
votes2
answers1864
viewsA: Junit 5 - How to run a test method only if another test method passes?
You can do this using Testng. Testng is a test framework that is done on top of Junit. For more details see documentation: http://testng.org/doc/documentation-main.html There are two ways to do this…
-
0
votes1
answer156
viewsA: Organize message from Thread
The problem is that the two threads are printing on the same console. At this point you print the chat string without line break. while(true){ System.out.print("[Chat]"+": "); // Aqui você imprime o…
-
0
votes1
answer41
viewsA: How to check an Imagepattern of a Rectangle in Javafx?
The method is returning false because the objects compared are different. In java, when you create a class, it inherits from the class Object. One of the methods of Object is the equals. The method…
-
0
votes1
answer431
viewsA: Write to txt file save, read and save to one in another txt file
I’m not sure I understand your problem correctly. See if this solution meets: import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import…
-
1
votes1
answer584
viewsA: Test with junit
In this case, you can check if the method worked as expected by checking the content that is being printed out. To do this, you can create your OutputStream and set it on System.setOut Following…
-
1
votes1
answer197
viewsA: Problem drawing chess board with objects
The problem is in the method drawGrid. The stop condition of the first loop is wrong. You are using a < when it should be a <=. private void drawGrid(int nRowsAndColumns) { int side = 50; for…
javafxanswered Fagner Fonseca 1,447 -
1
votes1
answer98
viewsA: List change from an Apache poi excel import
I think it is not worth loading the data from the spreadsheet and checking which ones have changed. You can simply replace the system data with the data from the spreadsheet. This approach will be…
-
1
votes1
answer1243
viewsA: Java Webview how to use
I couldn’t reproduce the problem. The problem may be in the way this method site is being called, or in how the method main is being mounted. Based on what you want to do in the future, I made an…
-
0
votes1
answer110
viewsA: How to modify phone field?
Just change the method mascara. The switch checks the size of the string, depending on the size, the mask characters are being added. In the old method, cases are adding parentheses in the first 2…
-
0
votes1
answer56
viewsA: exception of reflect.Invocationtargetexception
I created an example from the available code and it worked. A few things that might have influenced: I used the javafx Mediaplayer to play the song. The question does not say which class is being…
-
1
votes2
answers410
viewsA: Need to declare variables in a Javascript function
You do not need to declare again. You can do this: alert(exemplo(teste)) However, if you need to use this result in more than one place, in this case it is indicated to save the return in the…
-
0
votes1
answer460
viewsA: Label update in loop
The problem is that the code has only one thread. When the method playBotao is called, the screen is locked because the method is running on the same screen thread. Therefore, only after the method…
-
0
votes1
answer34
viewsA: Arrays not initialized
It depends on where this statement was made. If it is an attribute, the value is null. Attributes in java receive a default boot value. Any attribute that type is a class will be initialized as…
-
1
votes1
answer63
viewsA: java: how to access an object through a string
You can use the lookup method. It receives an id and returns a Node. But to use it you will need to set an id in the Labels. Example: public void start(Stage primaryStage) { try { GridPane gridPane…
-
0
votes1
answer73
viewsA: Testing RMI with Junit
You can create an Rmiregistry from java. I created a method setupClass with the Annotation @BeforeClass, In this method I created Registry and started the server. This annotation means that the…
-
0
votes1
answer768
viewsA: Test main class input method with Systemin drive in test class
Stop testing the System.out.println, you can create a OutputStream and pass it to the method System.setOut. That way, when the System.out.println is called, the output will be written in your…
-
0
votes1
answer153
viewsA: Java - Import Excel with combo and checkbox
Resolution with Apache POI. The reading of the combobox will be done in the same way as a normal cell. The only detail is the reading of the checkbox. This field is a boolean, when configuring it…
-
4
votes3
answers294
viewsA: Transform Set<Integer> into Set<String>
With java8, you can use the stream: import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; public class Main { public static void main(String args[]) {…
-
1
votes1
answer620
viewsA: How to read TXT to a certain point and then continue from that point?
You could save the Bufferedreader reference for later use. I made an example for you to have an idea: package stackoverflow.tests; import java.io.BufferedReader; import java.io.Closeable; import…
-
2
votes1
answer729
viewsA: Error: "Cannot find Symbol" - Class Instance within Main Class, using Linux terminal
This is classpath problem. If all classes are in the same package, Compile with this command: javac -cp .. MainEX1.java You need to tell the compiler where to find the classes needed to compile. The…
-
1
votes2
answers1210
viewsA: How to install Javafx?
javafx is included with jdk7, but it is not in the classpath. To use it you need to add the library manually to your project. Starting with jdk8, javafx is already configured in classpath. However,…
-
0
votes1
answer420
viewsA: How do I add a pane inside another pane via code like javafx?
Pane also has the method getChildren(). You can use it the same way as Anchorpane. Make sure you are using the correct import: import javafx.scene.layout.Pane; See the class documentation at this…
-
0
votes1
answer56
viewsA: Dúvidas Abstract Factory
The problem with its implementation is the return of methods. Abstractfactory is a pattern that serves precisely to create objects, in this case a family of objects. Therefore the methods void…
-
2
votes2
answers1066
viewsA: Java - Could not find main class
The error is in that call: java main You must use the full name of the class that in this case is: app1.main. However, it still won’t work. Java will try to enter an app1 package to find the class.…
-
1
votes3
answers534
viewsA: Reduce jar size in Maven Design
An alternative is to create the jar without the dependencies. The jar will contain only the project classes and will be greatly reduced. In that case, you’ll need to put the jars the project needs…
-
1
votes5
answers18470
viewsA: delete repeated values java array
With Java8: Integer[] ja = {1,2,3,3,4,5,6,6,8,9}; List<Integer> distinctList = Arrays.asList(ja).stream().distinct().collect(Collectors.toList());
javaanswered Fagner Fonseca 1,447 -
0
votes1
answer163
viewsA: Returning value 0 in a java this.Return
The problem is because you are printing before calculating the clearance. Reverse the order of the methods call atividadeInfo and R. Change that: atividadeInfo(atividades); R(atividades); For that…
javaanswered Fagner Fonseca 1,447 -
0
votes2
answers567
viewsA: Test without "fouling" (adding data) the database
It is usually recommended to use a memory bank to carry out the tests. The bank will be created and loaded only to test, at the end of the tests the bank will be destroyed. You can use the normal…
-
4
votes3
answers5014
viewsA: Testing a void method with mockito
In fact the mockite does not serve to test, it serves to create mocks of objects and methods. When I say it’s not for testing, I mean it won’t validate if the method worked as expected. So you…
-
8
votes2
answers6368
viewsA: HEAD is Detached in Repository
This happened because you checked out a commit. You probably should have executed this command git checkout a83c7867c2. Git has a guy named HEAD. HEAD points to the current branch. It’s through HEAD…
-
3
votes1
answer190
viewsQ: When should I wear a patch?
One of the features of git is the use of patches. When a patch should be used? I read that patches were designed for Hotfixes. However, I can’t understand why I would patch instead of just push the…
-
19
votes1
answer25509
viewsA: What exactly does git checkout branch -- . do?
The git checkout branch can be used in the following situations: 1 - Change branch. When git changes branch, all changes that were applied to the branch will be replaced by changes to the branch…
gitanswered Fagner Fonseca 1,447 -
1
votes1
answer2316
viewsA: Problems with the . jar
Failed to specify which class has the main. <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId>…
-
2
votes2
answers378
viewsA: Library loading at runtime
It is not contraindicated to load jars at runtime, on the contrary. Developing applications that work in this way is desirable. Because then we can change a part of the software without needing to…
-
0
votes2
answers153
viewsA: How to put 2 loop inside a list? or a second loop to a second list
I don’t quite understand what you want to do. But see if this solves: public static void main(String[] args) { List<Long> lista = null; for (long j = 1; j <= 5; j++) { lista = new…
javaanswered Fagner Fonseca 1,447 -
0
votes4
answers551
viewsA: When are branches useful in Git?
It turns out that in these two cases that I identified which branches would be useful, the utility comes from the fact that there is a stable code that is not interesting to move around and we want…
gitanswered Fagner Fonseca 1,447 -
1
votes1
answer165
viewsA: Am I abusing Strategy Pattern too much in Java?
I am abusing the Strategy Pattern in Java? The answer is yes. Project patterns should not be used inadvertently. For your case, you could have solved the problem in a simpler way. The implementation…
-
0
votes2
answers216
viewsA: Return information from a String
Possible solution: public class App { private List<String> keys; private String fraseParametro; private String frase; private Map<String, String> map; public App() { keys = new…
-
2
votes2
answers4863
viewsA: How to create a method with optional parameters in pure Java?
As described in Maniero’s reply there is no way to do this in Java. An alternative would be the following: Original method: void metodo(int arg1, String arg2, int arg3, String arg4, String arg5) { }…