image

Acesse bootcamps ilimitados e +650 cursos pra sempre

60
%OFF
Adriano Menezes
Adriano Menezes10/11/2022 11:48
Compartilhe

Teste para vaga Java Senior. Se passar no Teste você já está muito bem em Java.

  • #Java

Recentemente fiz um teste para Java Senior e gostaria de compartilhar com vocês para se alguém não conseguir resolver o problema, possa ter um caminho de onde precisa se aprofundar mais em Java. Alguém se habilita em tentar resolver o problema.

Segue o enunciado do teste em ingles:

The system you work with on a daily basis runs multiple microservices. You have been asked to prepare an
aggregation that represents number of user visits to all microservices, for use by data analysis.


The architect you are working with has already designed the API, which consists of a single class:VisitCounter.
VisitCounter has a single method,count.


It returns Map<Long , Long> - this map should contain the number of visits by the user with a given ID.


This method accepts an array of Map<String , UserStats>. Every Map represents the total number of visits per
user to a given microservice. There are some problems, however:


1. The Map key, which is a string, should be parseable to Long - but it may not be. You must skip any such
faulty entries.(())


2. for some keys, UserStats may be null. You must skip any such faulty entries.(())


3. UserStats has a single field, visitCount, of type Optional<Long>. A getter for this field is also
implemented. This field will never be null; however it might be empty. You must skip any such faulty
entries.(())


Remember that you may receive some invalid input: null,empty maps, and so on. Handle it all appropriately
and return an empty map/
You may use Java 8 Streams API to implement your solution.

Segue o código recebido para dar continuidade no teste.

import java.util.*;


public class Test {

  public static void main(String[] args) {
      
      class VisitCounter {
      
          Map<Long, Long> count(Map<String, UserStats >... visits) {
              return null;
          }
      }
  }
}

Compartilhe
Comentários (0)